412 - Pi

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Thu Mar 27, 2008 8:15 pm

Try the set.

Input:

Code: Select all

6
1
31727
490
407
677
29070
0
Output:

Code: Select all

2.535463
Hope it helps.

rhsumon
New poster
Posts: 48
Joined: Wed Aug 23, 2006 12:29 pm
Location: Dhaka

Re: 412 - WA (Can't find the big from posts before <- -a>)

Post by rhsumon » Sat Aug 16, 2008 10:00 pm

Where i the problem here
I can't fix
Plz take a look

Code: Select all

Silly Mitake 
Anyway AC now
Plz help anyone

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

Re: 412 - WA (Can't find the big from posts before <- -a>)

Post by pok » Sun Jan 04, 2009 10:55 pm

Why WA ?
cant find any mistake..
pls someone help me..

Code: Select all

removed after AC..
need ur help.. :(
Last edited by pok on Mon Jan 05, 2009 12:48 am, edited 1 time in total.

Articuno
Learning poster
Posts: 78
Joined: Sun Nov 30, 2008 5:00 pm
Location: IUT-OIC, Dhaka, Bangladesh

Re: 412 - WA (Can't find the big from posts before <- -a>)

Post by Articuno » Sun Jan 04, 2009 11:25 pm

Check this line:
Answers must be rounded to six digits after the decimal point.
Good luck :)
May be tomorrow is a better day............ :)

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

Re: 412 - WA (Can't find the big from posts before <- -a>)

Post by pok » Mon Jan 05, 2009 12:47 am

Thanks a lot..
Take care.. & God bless you..
:D

User avatar
Jordi Aranda
New poster
Posts: 13
Joined: Wed Apr 29, 2009 11:37 am
Location: Barcelona

Re: 412 - WA (Can't find the big from posts before <- -a>)

Post by Jordi Aranda » Mon Aug 03, 2009 1:50 pm

I don't pass the proposed inputs in this thread but I don't know what I'm doing wrong. Here's my code:

Code: Select all

Removed after accepted
It seems that for large inputs, something is wrong with my code and gives a wrong expected pi.
Last edited by Jordi Aranda on Mon Aug 03, 2009 11:20 pm, edited 1 time in total.
Born to be wild

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 412 - Pi

Post by mf » Mon Aug 03, 2009 2:51 pm

In this line:
double expected_pi = sqrt(6*npairs/compta);
you have an integer division, which rounds the result of division down to the nearest integer.

Use something like:

Code: Select all

double expected_pi = sqrt(6*npairs/(double)compta);
  or:
double expected_pi = sqrt(6.0*npairs/compta);

User avatar
Jordi Aranda
New poster
Posts: 13
Joined: Wed Apr 29, 2009 11:37 am
Location: Barcelona

Re: 412 - Pi

Post by Jordi Aranda » Mon Aug 03, 2009 11:21 pm

Thanks again mf :)
Born to be wild

kawsar
New poster
Posts: 12
Joined: Thu Aug 05, 2010 7:40 pm

412 Wrong answer

Post by kawsar » Thu Aug 05, 2010 8:27 pm

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

long a[1000000];

int main(){
long n, i, j, x, p, q ;

while(scanf("%ld",&n)==1){
long num =0, sum=0;
if(n == 0)
return 0;

for(i=0; i<n; i++)
scanf("%ld",&a);


for(i=0; i<n; i++){
for(j=i+1; j<n; j++){
num++;

if(a == 1 && a[j]==1){
sum++;
continue;
}


x = a % a[j];
p = a[j];

while(x != 0){
if(x == 1){
sum++ ;
break ;
}
q = x ;
x = p % x ;
p = q ;
}

}
}

if(sum == 0)
printf("No estimate for this data set.\n");
else
printf("%.6f\n",sqrt((6/(float)sum)*num));
}
return 0;
}


//In every time i got wrong answer. why ??

kawsar
New poster
Posts: 12
Joined: Thu Aug 05, 2010 7:40 pm

412 - Some spacial input-output for 412 program

Post by kawsar » Wed Aug 18, 2010 8:10 am

I found every time Wrong Answer for this problem...
Is there any spacial input output for this problem ???

If there , then any one please give me the input output.... I am so fucked up for this problem...
Help me...........!!! :( :( :(

shatil_cse
New poster
Posts: 11
Joined: Thu Apr 05, 2012 8:33 pm

Re: 412 - Some spacial input-output for 412 program

Post by shatil_cse » Wed May 02, 2012 7:34 pm

please help me ....
don't know why WA!!!!!!!!!!

Code: Select all

//code removed after AC
Last edited by shatil_cse on Thu May 03, 2012 5:15 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 412 - Some spacial input-output for 412 program

Post by brianfry713 » Wed May 02, 2012 11:23 pm

On my machine your code prints 0.000000 for the first sample input. Your printf is using %Lf or long double, but sqrt returns a %lf or double.
Check input and AC output for thousands of problems on uDebug!

shatil_cse
New poster
Posts: 11
Joined: Thu Apr 05, 2012 8:33 pm

Re: 412 - Some spacial input-output for 412 program

Post by shatil_cse » Thu May 03, 2012 5:13 pm

brianfry713 wrote:On my machine your code prints 0.000000 for the first sample input. Your printf is using %Lf or long double, but sqrt returns a %lf or double.
Oh got AC ........
So thanks bosssssss

tansif.ruetcse13
New poster
Posts: 2
Joined: Tue Nov 25, 2014 2:35 pm

Re: 412 - Pi

Post by tansif.ruetcse13 » Sun Mar 22, 2015 1:58 pm

Code: Select all

#include<stdio.h>
#include<math.h>
int main()
{
    int i,j,a[50],d,temp,N,t;
    while(1)
    {
    d=0,t=0;
    scanf("%d",&N);
    if(N==0)
    break;
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<N-1;i++)
    {
        for(j=i+1;j<N;j++)
        {
            if(a[i]<a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    for(i=0;i<N-1;i++)
    {
        for(j=i+1;j<N;j++)
        {
            if((a[i]%a[j]!=0))
            {
                if((a[i]%2!=0)||(a[j]%2!=0))
                d++;
            }
            t++;
        }
    }
    if(d==0)
    printf("No estimate for this data set.\n");
    else
    printf("%.6lf\n",sqrt((6*t)/d));
}
return 0;
}
why wa??
Last edited by brianfry713 on Mon Mar 30, 2015 11:50 pm, edited 1 time in total.
Reason: Added code block

tansif.ruetcse13
New poster
Posts: 2
Joined: Tue Nov 25, 2014 2:35 pm

Re: 412 - Pi why wa???

Post by tansif.ruetcse13 » Sun Mar 22, 2015 2:22 pm

Code: Select all

#include<stdio.h>
#include<math.h>
int main()
{
    int i,j,a[50],d,temp,N,t;
    while(1)
    {
    d=0,t=0;
    scanf("%d",&N);
    if(N==0)
    break;
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<N-1;i++)
    {
        for(j=i+1;j<N;j++)
        {
            if(a[i]<a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    for(i=0;i<N-1;i++)
    {
        for(j=i+1;j<N;j++)
        {
            if((a[i]%a[j]!=0))
            {
                if((a[i]%2!=0)||(a[j]%2!=0))
                d++;
            }
            t++;
        }
    }
    if(d==0)
    printf("No estimate for this data set.\n");
    else
    printf("%.6lf\n",sqrt((6*t)/d));
}
return 0;
}
Last edited by brianfry713 on Mon Mar 30, 2015 11:49 pm, edited 1 time in total.
Reason: Added code block

Post Reply

Return to “Volume 4 (400-499)”