Page 1 of 2
10451 - Ancient Village Sports
Posted: Wed Feb 26, 2003 11:48 pm
by 2481RE
I have encountered following problem:
I cannot use M_PI defined in math. In the description is:
more less PI = 2 * cos^-1 (0)
How to code it? I tried 2/cos(0) but it didn't work.
And I tried also #define PI = 3.14159265358979323846,
but it didn't work either (example set works fine but I've got WA)
Posted: Thu Feb 27, 2003 1:42 am
by turuthok
I believe cos^-1 right there means the inverse function of cos ... which is acos().
-turuthok-
Re: 10451
Posted: Thu Feb 27, 2003 1:13 pm
by bery olivier
2481RE wrote:I tried 2/cos(0) but it didn't work.
This doesn't work cause 2/cos(0)=2/0 !!!!!!
Better use the definition as turuthok said or cos^-1(-1)
PI=2*acos(0)=acos(-1)
Posted: Thu Feb 27, 2003 2:03 pm
by turuthok
bery, cos(0) == 1, right ???
-turuthok-
if someone could give me any test cases...
Posted: Thu Feb 27, 2003 2:10 pm
by 2481RE
OK - I tried 2*acos(0) - and for all test cases worked fine, but, still got WA. And I have no idea why. Can anyone send me more test cases?
Shame
Posted: Thu Feb 27, 2003 2:40 pm
by bery olivier

I'm so ashamed
Sure it's 1 and not 0. Sorry for that. I should stop alcohol.
Posted: Fri Feb 28, 2003 4:09 pm
by 2481RE
Can anyone tell me what's wrong?
area_r = (2 * acos(0)) * (area/(n*tan((2 * acos(0))/n)));
area_R = (2 * acos(0)) * 2*area/(n*sin(2*(2 * acos(0))/n));
spectators = area_R - area;
officials = area - area_r;
that's my algo, which works fne for test cases, but I receive WA...
Posted: Fri Feb 28, 2003 10:52 pm
by turuthok
My algo is slightly different than yours ... specially in the
area_R calculation.
area_r = (2 * acos(0)) * (area/(n*tan((2 * acos(0))/n)));
area_R = (2 * acos(0)) * 2*area/(n*sin(2*(2 * acos(0))/n));
Based on area_r calculation, we can tell that r^2 = (area/(n*tan(PI/n)).
You will notice that R (bigger radius) is in fact can be derived from the smaller r ... I'm sure you'll see the connection between those two.
Try to get R and update your area_R with simply PI * R * R ... and see what happens.
-turuthok-
Posted: Sat Mar 01, 2003 1:14 pm
by 2481RE
Thanks a lot for help. Both algos were good. The problem was precision.
When I used double instead of float I got accepted.

10451(Ancient Village Sports) WA
Posted: Wed Jul 28, 2004 3:17 am
by midra
I got WA in this problem...but it is so rare because with the sample input it doesn't gives me exactly the sample output, it is different in the last decimal (fifth decimal)
I know it is large, but the code is short, just the explaining is large...
Here is my code and then how I made it:
[c]
#include <stdio.h>
#include <math.h>
#define pi 2*acos(0.0)
int main()
{
int n,temp=0;
float a;
float angle,radio,base,height,total1,total2;
while(1){
temp++;
scanf("%d %f",&n,&a);
if (n<3)
break;
angle=sin((360/(2*n)*pi/180));
angle=angle*2;
base=((2*a/n)*(2*a/n));
base/=(1/(angle*angle))-0.25;
base=pow(base,1/4);
height=((a/n)*2)/base;
radio=sqrt(base/2*base/2 + height*height);
total1=pi*radio*radio - a;
total2=a-pi*height*height;
printf("case %d: %f %f\n",temp,total1,total2);
}
return 0;
}[/c]
the code is just the formulas but here is how I get this formulas:
They give me the Total Area and the n-sides of the polygon, so I can divide the polygon in n traingles or better, in 2*n triangles rectangles, (because with the triangles rectangles I can use trigonometry)
well... I know that every trangle has a 90
Posted: Wed Jul 28, 2004 7:16 am
by sohel
Hi Midra,
Your method seems to be correct but you made some mistakes in your coding. Here are some of those:
1]
[c] base=pow(base,1/4); [/c]
---- > remember 1/4 = 0 and not 0.25.
2] [c]printf("case %d: %f %f\n",temp,total1,total2);[/c]
---->
C should be capital in 'Case' or you will get PE.
----> you have to output the answers to 5 decimal places but
%f will give 6 decimal places.... use %.5f.
3] In questions where you have to output answers to small decimal places use double... float will invariably give you wrong answers.
I have modified these and got AC. Check your PM if you want to see the modified code.
Hope it helps.

10451 WA... plz help
Posted: Mon Jan 30, 2006 7:17 pm
by georgemouse
I've changed many ways to do this problem......but still WA.
What is wrong? Can someone tell me....
Posted: Mon Jan 30, 2006 7:36 pm
by helloneo
you need to read IO condition carefully..
In each line of the input file there is an integer n (0<n<=50) and a floating-point number A (0<=A<=30000). A line with the value of n is less than three, terminates the input
you might want to change this line..
10451, WHY WA?
Posted: Mon Jun 26, 2006 4:45 pm
by deena sultana
I got WA in 10451. i dont understand what wrong i did.
Is anyone there 2 help me?
Plz help.
Posted: Mon Jun 26, 2006 8:39 pm
by sohel
hello deena-
These types of problem are precision error prone and hence the use of float is kinda risky..
.. infact never use float.

always use double !!!
Your above code should get AC after the switch.