412 - Pi
Moderator: Board moderators
Edit your post and remove your code. For 10489, post it in the correct section.
Ami ekhono shopno dekhi...
HomePage
HomePage
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.
Here's my code......
It gave me the correct outputs for the inputs in the fourm, but still WA......
Can somebody help me please?
I appreciate that.
Thank you Jan!!
It gave me the correct outputs for the inputs in the fourm, but still WA......
Can somebody help me please?
I appreciate that.
Code: Select all
Code removed after AC.
Last edited by gba356 on Wed Jun 06, 2007 4:09 am, edited 1 time in total.
Try the case below. (I have changed the input format, you can reformat it if necessary)
Input:
Output:
Hope it helps.
EDIT: A second look:
Function Prime() is not fully correct and looks complicated. This function can be written simply.
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
Code: Select all
2.761513
EDIT: A second look:
Function Prime() is not fully correct and looks complicated. This function can be written simply.
Ami ekhono shopno dekhi...
HomePage
HomePage
output input all right 412 WA
Last edited by bishop on Tue Jun 19, 2007 7:45 pm, edited 1 time in total.
-
- Learning poster
- Posts: 60
- Joined: Sun Apr 16, 2006 7:59 pm
hello...
convert all float to double and change..
into
hope it helps...
convert all float to double and change..
Code: Select all
if(count)
printf("%.6f\n",res);
Code: Select all
if(count)
printf("%lf\n",res);
-
- 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...
2all: To get AC - use double and only double. Not long double or float!!
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
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
my profile
-
- 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!!!
Unbelievable!!!
Now I lay me down to sleep...
my profile
my profile
-
- 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;
}
-
- New poster
- Posts: 1
- Joined: Wed Mar 19, 2008 5:35 pm
- Location: DHAKA......(Bangladesh)....
- 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;
}
Not for Me...........