10451 - Ancient Village Sports
Moderator: Board moderators
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)
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)
-
- Learning poster
- Posts: 90
- Joined: Sat Feb 15, 2003 1:39 am
- Location: Paris, France
- Contact:
Re: 10451
This doesn't work cause 2/cos(0)=2/0 !!!!!!2481RE wrote:I tried 2/cos(0) but it didn't work.
Better use the definition as turuthok said or cos^-1(-1)
PI=2*acos(0)=acos(-1)
Not AC yet
AC at last 


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?
-
- Learning poster
- Posts: 90
- Joined: Sat Feb 15, 2003 1:39 am
- Location: Paris, France
- Contact:
Shame


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


-
- 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.
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-
Based on area_r calculation, we can tell that r^2 = (area/(n*tan(PI/n)).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));
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).
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;
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
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
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.

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.

-
- 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....
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.
you need to read IO condition carefully..
you might want to change this line..
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;
-
- New poster
- Posts: 36
- Joined: Mon Jun 19, 2006 5:43 pm
- Location: Bangladesh
- Contact:
10451, WHY WA?
I got WA in 10451. i dont understand what wrong i did.
Is anyone there 2 help me?
Plz help.
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.