ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1020. Ниточка

JAVA, test 3, what is wrong?
Послано ssau6207Voekov 18 ноя 2015 01:50
import java.io.*;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.*;

public class p2015_11_17_DZnaOlympSSAU_Timus1020_Thread implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    public static void main(String[] args) {
        new Thread(null, new p2015_11_17_DZnaOlympSSAU_Timus1020_Thread(), "", 256 * (1L << 20)).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            init();
            solve();
            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    void solve() throws IOException {
        int numberOfNails=readInt();

        double radiusOfNails=readDouble();
        if (numberOfNails==1){
            out.println(2*PI*radiusOfNails);
        } else {
            double xFirstNail = readDouble();
            double yFirstNail = readDouble();

            double xLastNail=xFirstNail;
            double yLastNail=yFirstNail;

            double xOfTheCurrentNail=xFirstNail;
            double yOfTheCurrentNail=yFirstNail;

             double lengthOfTheThread=0;

            for (int currentNail = 2; currentNail <= numberOfNails; currentNail++) {
                xLastNail=xOfTheCurrentNail;
                yLastNail=yOfTheCurrentNail;
                xOfTheCurrentNail=readDouble();
                yOfTheCurrentNail=readDouble();
                lengthOfTheThread+=(Math.sqrt((xOfTheCurrentNail-xLastNail)*(xOfTheCurrentNail-xLastNail)+(yOfTheCurrentNail-yLastNail)*(yOfTheCurrentNail-yLastNail)));
            }

            lengthOfTheThread+=(Math.sqrt((xFirstNail-xOfTheCurrentNail)*(xFirstNail-xOfTheCurrentNail)+(yFirstNail-yOfTheCurrentNail)*(yFirstNail-yOfTheCurrentNail)));
            lengthOfTheThread+=(2*PI*radiusOfNails);
            System.out.println( String.format("%.2f", lengthOfTheThread) );
        }
    }
}
Re: JAVA, test 3, what is wrong?
Послано ssau6207Voekov 18 ноя 2015 09:43
I found a problem. When n==1, program print (2*PI*radiusOfNails), but must ("%.2f",2*PI*radiusOfNails)