ENG  RUS Timus Online Judge Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1020. Rope

что не так?
Posted by Kovalyshyn Artur 9 Feb 2017 18:15
import java.text.DecimalFormat;
import java.util.Scanner;

/**
* Created by user on 06.02.2017.
*/
public class nytka {
public static void main(String[] args) {
double c = 0;
Scanner sc = new Scanner(System.in);
String a = sc.next();
int b = Integer.valueOf(a);
String q = sc.next();
double r = Double.valueOf(q);
double[] x = new double[b];
double[] y = new double[b];
if (100>b) {
if (b > 0){
for (int i = 0; i <= b - 1; i++) {
String x2 = sc.next();
double x1 = Double.valueOf(x2);
x[i] = x1;
String y2 = sc.next();
double y1 = Double.valueOf(y2);
y[i] = y1;

}
for (int i = b - 1; i > 0; i--) {
double rez = Math.sqrt(((x[i] - x[i - 1]) * (x[i] - x[i - 1])) + ((y[i] - y[i - 1]) * (y[i] - y[i - 1])));
c = c + rez;
}
}
}
double end = Math.sqrt(((x[b-1]-x)*(x[b-1]-x))+((y[b-1]-y)*(y[b-1]-y)));
c = c + end;
double endrez = c + rad;
DecimalFormat f = new DecimalFormat("#,##0.00");
System.out.print(f.format(endrez));
}
}
Re: что не так?
Posted by ToadMonster 9 Feb 2017 19:16
You should clarify error - WA/TLE/runtime; and show test number.

b can be 100 by task description.
b can be 1 by task description.

Conditions like "if (b correct) then solve else do nothing" are useless.
Ok, you found b==102. So what? How should you check if WA is because program mistake or because you detected invalid b?

Usually if input data can be invalid then some specific program behavior is declared and required.
Here - on timus - input is supposed to be always valid, no any input-error-behavior expected.
You should fail program in specific way (different from regular WA) this case or remove condition at all.

Edited by author 09.02.2017 19:21