10432 - Polygon Inside A Circle
Moderator: Board moderators
Re: 10432 - Polygon Inside A Circle
the problem is precision... replace 3.141592 by acos(-1).
-
- New poster
- Posts: 1
- Joined: Fri Jul 18, 2014 10:04 pm
Re: 10432 - Polygon Inside A Circle
my answers are correct, but i get runtime error, if somebody could get me started
Code: Select all
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) {
// TODO code application logic here
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String line;
ArrayList<Integer> radius = new ArrayList<>();
ArrayList<Integer> numSides = new ArrayList<>();
try {
while((line = stdin.readLine()) != null && line.length() != 0){
radius.add(Integer.parseInt(line.split(" ")[0]));
numSides.add(Integer.parseInt(line.split(" ")[1]));
}
} catch (IOException ex) {
}
int i = 0;
double halfTheta;
while(i < radius.size()){
halfTheta = (Math.PI)/numSides.get(i);
System.out.println(Math.cos(halfTheta)*Math.sin(halfTheta)*(Math.pow(radius.get(i), 2))*numSides.get(i));
i++;
}
}
}
Re: 10432 - Polygon Inside A Circle
The method your program uses to read input is too inflexible, which is often an issue in problems from UVa's archives. What does your program do if a test case contains spaces at the beginning of the line, or at the end, or more than one space between the two numbers?vinitmuchhala wrote:my answers are correct, but i get runtime error, if somebody could get me started
Also, pay close attention to the output specification: The number must be rounded to the third digit after the decimal point.