## 10451 - Ancient Village Sports

Moderator: Board moderators

2481RE
New poster
Posts: 4
Joined: Wed Feb 26, 2003 11:40 pm
Location: Poland

### 10451 - Ancient Village Sports

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)

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:
I believe cos^-1 right there means the inverse function of cos ... which is acos().

-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).

bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:

### Re: 10451

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)
Not AC yet AC at last

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:
bery, cos(0) == 1, right ???

-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).

2481RE
New poster
Posts: 4
Joined: Wed Feb 26, 2003 11:40 pm
Location: Poland

### if someone could give me any test cases...

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?

bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:

### Shame

I'm so ashamed
Sure it's 1 and not 0. Sorry for that. I should stop alcohol.
Not AC yet AC at last

2481RE
New poster
Posts: 4
Joined: Wed Feb 26, 2003 11:40 pm
Location: Poland
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...

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:
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-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).

2481RE
New poster
Posts: 4
Joined: Wed Feb 26, 2003 11:40 pm
Location: Poland
Thanks a lot for help. Both algos were good. The problem was precision.
When I used double instead of float I got accepted.

midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

### 10451(Ancient Village Sports) WA

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;
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;
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

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
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.

georgemouse
New poster
Posts: 13
Joined: Sun Aug 28, 2005 3:39 pm
Location: Taiwan

### 10451 WA... plz help

I've changed many ways to do this problem......but still WA.
What is wrong? Can someone tell me....

Code: Select all

``removed after AC``
Last edited by georgemouse on Tue Jan 31, 2006 4:08 pm, edited 1 time in total.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
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..

Code: Select all

``````    if(n==0) break;
``````

deena sultana
New poster
Posts: 36
Joined: Mon Jun 19, 2006 5:43 pm
Contact:

### 10451, WHY WA?

I got WA in 10451. i dont understand what wrong i did.

Is anyone there 2 help me?

Plz help.

Code: Select all

``````
Removed After AC.
``````
Last edited by deena sultana on Mon Jun 26, 2006 9:16 pm, edited 1 time in total.

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
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.