10451 - Ancient Village Sports

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

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

10451 - Ancient Village Sports

Post by 2481RE » Wed Feb 26, 2003 11:48 pm

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:

Post by turuthok » Thu Feb 27, 2003 1:42 am

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

Post by bery olivier » Thu Feb 27, 2003 1:13 pm

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 Image AC at last Image

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok » Thu Feb 27, 2003 2:03 pm

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

Post by 2481RE » Thu Feb 27, 2003 2:10 pm

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

Post by bery olivier » Thu Feb 27, 2003 2:40 pm

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

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

Post by 2481RE » Fri Feb 28, 2003 4:09 pm

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:

Post by turuthok » Fri Feb 28, 2003 10:52 pm

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

Post by 2481RE » Sat Mar 01, 2003 1:14 pm

Thanks a lot for help. Both algos were good. The problem was precision.
When I used double instead of float I got accepted. :D

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

10451(Ancient Village Sports) WA

Post by midra » Wed Jul 28, 2004 3:17 am

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

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel » Wed Jul 28, 2004 7:16 am

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. :roll:

2] [c]printf("case %d: %f %f\n",temp,total1,total2);[/c] :o

----> 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.
:wink:

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

10451 WA... plz help

Post by georgemouse » Mon Jan 30, 2006 7:17 pm

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

Post by helloneo » Mon Jan 30, 2006 7:36 pm

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
Location: Bangladesh
Contact:

10451, WHY WA?

Post by deena sultana » Mon Jun 26, 2006 4:45 pm

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.

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel » Mon Jun 26, 2006 8:39 pm

hello deena-

These types of problem are precision error prone and hence the use of float is kinda risky..

.. infact never use float. :D always use double !!!

Your above code should get AC after the switch.

Post Reply

Return to “Volume 104 (10400-10499)”