412 - Pi

Moderator: Board moderators

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Edit your post and remove your code. For 10489, post it in the correct section.
Ami ekhono shopno dekhi...
HomePage

henry1007
New poster
Posts: 4
Joined: Thu Apr 19, 2007 7:28 pm
I hv also tried 412. The first time I count {2, 7, 2} as one pair only and get WA. Then I remove the part checking repeated numbers - count {2, 7, 2} as 3 pairs and get AC. So I think the problem supposes repeated numbers are seen as distinct ones. It make sense actually - we calculate pi by a RANDOM collection of numbers. By randomness repeated numbers are natural. Removing repeated ones disturbs the randomness.

gba356
New poster
Posts: 15
Joined: Sat Apr 28, 2007 10:12 am
Location: Taiwan
Here's my code......
It gave me the correct outputs for the inputs in the fourm, but still WA......
I appreciate that.

Code: Select all

``````Code removed after AC.
``````
Thank you Jan!!
Last edited by gba356 on Wed Jun 06, 2007 4:09 am, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Try the case below. (I have changed the input format, you can reformat it if necessary)

Input:

Code: Select all

``````37
9624 19554 20737 18465 17400 7234 8610 20921 1 31727 27779 17313 490 407 677 12325 17115 29070 18337 6863 27974 27982 13463 16266 6011 5053 1896 21767 3191 30382 29221 20064 5885 2473 24263 24571 745
0``````
Output:

Code: Select all

``2.761513``
Hope it helps.

EDIT: A second look:
Function Prime() is not fully correct and looks complicated. This function can be written simply.
Ami ekhono shopno dekhi...
HomePage

gba356
New poster
Posts: 15
Joined: Sat Apr 28, 2007 10:12 am
Location: Taiwan

Thanks!

Thanks a LOT!!
I found my Prime() function cannot deal with the number 1, so I used another recursive GCD().

I got AC eventually, THANKS!!
Last edited by gba356 on Sat Jan 12, 2008 7:49 am, edited 1 time in total.

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

output input all right 412 WA

what wrong i this code
plz help abt WA

Code: Select all

``````code Remove d

``````
Last edited by bishop on Tue Jun 19, 2007 7:45 pm, edited 1 time in total.

ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm
hello...

convert all float to double and change..

Code: Select all

``````if(count)
printf("%.6f\n",res);
``````
into

Code: Select all

``````if(count)
printf("%lf\n",res);

``````
hope it helps...

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm
Thanks
it works

it accepted by %.6lf

andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:
Hello everyone!
I am posting here because every test I have found in this thread passes OK, but Judge tells me I got WA. I think it is again because of precision. I use gcd and sqrt funtions...

Code: Select all

``````ACC :) :D
``````
2all: To get AC - use double and only double. Not long double or float!!
Last edited by andysoft on Sat Jul 21, 2007 9:06 pm, edited 1 time in total.
Now I lay me down to sleep...
my profile

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
Try to use "double" instead of "float" ..

andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:
Man, I swear, 15 minutes ago, with double it didnt work. That's why I changed for float. And now when I changed float to double it got AC!!..
Unbelievable!!!
Now I lay me down to sleep...
my profile

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
Can you remove your code if you got AC..?
Good for you anyway..

torifat
New poster
Posts: 2
Joined: Wed Nov 28, 2007 11:40 pm
Location: Infront of PC [EWU]
Contact:

WA

Why WA??

Code: Select all

``````#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int gcd(int a, int b) {
if(b==0) return a;
return gcd(b,a%b);
}

int list[55];

int main() {

int n,i,j;

while(scanf("%d",&n)==1) {
if(n==0) break;

for(i=0; i<n; ++i)
scanf("%d",&list[i]);

int cnt=0;

for(i=0; i<n; ++i)
for(j=i+1; j<n; ++j)
if(gcd(list[i],list[j])==1) cnt++;

if(cnt==0) printf("No estimate for this data set.\n");
else {

double c = (double) (n*(n-1)/2);
c=((c*6.0)/(double) cnt)+0.00000001;
c=sqrt(c)+0.00000001;

printf("%.6lf\n",c);
}

}

return 0;
}``````

torifat
New poster
Posts: 2
Joined: Wed Nov 28, 2007 11:40 pm
Location: Infront of PC [EWU]
Contact:
Got AC

niloy
New poster
Posts: 1
Joined: Wed Mar 19, 2008 5:35 pm
Contact:

Why Wrong ANS......

Code: Select all

``````#include<stdio.h>
#include<math.h>

int is_CommonFact(int a,int b)
{	int temp;
if(a==1||b==1)
return 0;
else
{
if(b>a)
{
temp=b;
b=a;
a=temp;
}
while(b)
{
temp=a%b;
a=b;
b=temp;
}
if(a==1)
return 1;
else
return 0;
}
}

int main(void)
{

int n,count;
int i,j,a[55];

while(scanf("%d",&n)==1&&n)
{
count=0;
for(i=0;i<n;i++)
{	scanf("%d",&a[i]);
for(j=i-1;j>=0;j--)
if(is_CommonFact(a[j],a[i])==1)
count++;
}

if(count==0) printf("No estimate for this data set.\n");
else {

double PI = (double) (n*(n-1)/2);
PI=(PI*6.0)/(double) count;
PI=sqrt(PI);

printf("%.6lf\n",PI);
}
}

return 0;
}``````
[Edited by Jan. Use code tags]
Not for Me...........