10432 - Polygon Inside A Circle

All about problems in Volume 104. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

mpin3da
New poster
Posts: 1
Joined: Tue Mar 27, 2012 3:23 pm

Re: 10432 - Polygon Inside A Circle

Post by mpin3da »

the problem is precision... replace 3.141592 by acos(-1).
vinitmuchhala
New poster
Posts: 1
Joined: Fri Jul 18, 2014 10:04 pm

Re: 10432 - Polygon Inside A Circle

Post by vinitmuchhala »

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++;
        }
    }
}
lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 10432 - Polygon Inside A Circle

Post by lbv »

vinitmuchhala wrote:my answers are correct, but i get runtime error, if somebody could get me started
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?

Also, pay close attention to the output specification: The number must be rounded to the third digit after the decimal point.
Post Reply

Return to “Volume 104 (10400-10499)”