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

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Mon Feb 23, 2004 12:27 pm

I tried compiling your code usung TC 3.0 and I get the following error message:
Compiling NONAME00.CPP:
Error NONAME00.CPP 46: Cannot convert 'unsigned int *' to 'int *'
Error NONAME00.CPP 46: Type mismatch in parameter 'a' in call to 'present(int
Warning NONAME00.CPP 79: Function should return a value

helmet
New poster
Posts: 31
Joined: Tue Mar 02, 2004 11:55 am

Post by helmet » Fri Mar 05, 2004 5:06 pm

Apart from the compile errors the ealier guy got(which doesnt make any sense cause I think the code is correct)
try to change total and p to double;input them as integers if u want but since you are using them in the expression as it is, it will not always work.
Just another brick in the wall...

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

412 > need input/output, PLZ.

Post by _.B._ » Wed Mar 17, 2004 10:31 pm

Greetings!.
Will really appreciate good input/output for this problem.
Also, what'll be the output for this?:

2
4
4
3
2
7
2
0

Thanks in advance.
Bernardo L.

User avatar
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 » Wed Mar 17, 2004 11:20 pm

Output:
No estimate for this data set.
3.000000

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Thanks!.

Post by _.B._ » Thu Mar 18, 2004 8:06 pm

Greetings!.
Thanks for the quick response! :D
Going to try to solve it again...
Now, any other sugesstions for critic Input/Output?.
Thanks again!.
_.B._

rlatif119
New poster
Posts: 16
Joined: Mon Mar 01, 2004 4:00 pm
Location: Dhaka

412.....WA

Post by rlatif119 » Sat Apr 03, 2004 9:15 am

[c]
#include<stdio.h>
#include<math.h>

int gcd(int x,int y);

main()
{
int n,i,j,pair,count,ratio,val[100];
float pi;
while(1)
{
scanf("%d",&n);
if(n==0)
break;
for(i=0;i<n;++i)
scanf("%d",&val);
pair=0;count=0;
for(i=0;i<n-1;++i)
for(j=i+1;j<n;++j)
{
ratio=gcd(val,val[j]);
if(ratio==1)
++count;
++pair;
}
if(count>0)
{
pi = sqrt((6.0/(float)count)*(float)pair);
printf("%0.6f\n",pi);
}
else
printf("No estimate for this data set.\n");
}
}
int gcd(int x,int y)
{
int mod;
while(1)
{
mod=x%y;
if(mod==0)
break;
else
{
x=y;
y=mod;
}
}

return y;
}
[/c]

I think i am using the right algo. not only that i got correct answer for different inputs. But judges are always giving me WA.
can anybosy please help me to get out of the problem?
:roll:

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

WA!!.

Post by _.B._ » Wed Apr 07, 2004 9:54 am

Greetings.
Why is it 3.000000 the output for?:

Code: Select all

3
2
7
2
0
What will be output for this?:

Code: Select all

5
2       
3          
4 
5
6    
2          
13                                                                                      
39
6
2    
3     
4
5
2
4   
5       
2
5
3
2         
4 
2
4
4
3
2
7
2
0
Thanks in advance.
_.

User avatar
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 » Wed Apr 07, 2004 5:35 pm

The 2's are considered as different (I actually think all the integers given will be unique).
3.162278
No estimate for this data set.
3.162278
2.927700
No estimate for this data set.
3.000000

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Post by _.B._ » Wed Apr 07, 2004 10:08 pm

UFP2161
A great helper
A great helper indeed!!.
Thanks!!.
Got my AC finally!!.
I made such procedures to evaluate ONLY unique pairs...
Thanks!! :D
Keep posting!.
_.

Kentaro
New poster
Posts: 19
Joined: Thu Feb 05, 2004 4:41 am
Location: Canada, eh?

Post by Kentaro » Fri Apr 23, 2004 10:33 pm

Yeah, your code looks like it triggers integer division by mistake when printing out the estimate. You don't want integer division here. Try changing the 6 to 6.0 in your printf; that should trigger floating point division which you do want.

Or you can do as the previous poster suggested and change total and p to doubles.
Computer Science is no more about computers than Astronomy is about telescopes.
-- E. W. Dijkstra

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

412. Compile error....WHY!!!

Post by midra » Wed May 26, 2004 12:08 am

I am really confused about this.
Why I get Compile error in this problem???

Here is my code:

[c]
#include <stdio.h>
#include <math.h>

int gcd(int p,int q)
{
if (q>p)
return(gcd(q,p));
int g;
if (q==0)
return(p);
g=gcd(q,p%q);
return(g);
}

int main()
{
int n; /*Number of Numbers*/
int num[52];
int i,j,x; /*Counters*/
int temp;
float tot;
float res;
while(1)
{
scanf("%d",&n);
temp=0;
if (n==0)
break;
for (i=1;i<=n;i++)
scanf("%d",&num);
for (j=1;j<i;j++)
for (x=j+1;x<i;x++)
if (gcd(num[j],num[x])==1)
temp++;

tot=n*((n-1)/2);
res=sqrt(tot);

if (temp==0)
printf("No estimate for this data set.\n");
else
printf("%f\n",res);
}
return 0;
}[/c]

User avatar
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 » Wed May 26, 2004 12:48 am

Edit your profile and have the judge send results back to you by email. For CE, it will give you the exact output of the compiler.

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

Post by midra » Wed May 26, 2004 4:51 am

thanks a lot! I didn't know that.
I get this answer:
02546511_24.c: In function `gcd':
02546511_24.c:8: parse error before `int'
02546511_24.c:11: `g' undeclared (first use in this function)
02546511_24.c:11: (Each undeclared identifier is reported only once
02546511_24.c:11: for each function it appears in.)
Why is that??
The code compiles in my computer (Dev-cpp Win98s) and works fine.
I think the function gcd is right!
Why says 'parse error before int'. and Why 'g undeclared'??? g is declared!!! I imagine there is some incompatibility between compiler in Linux and Windows, but I don't have Linux ... :oops: so I don't know what is exactly wrong in my code...
someone knows????

User avatar
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 » Wed May 26, 2004 4:54 am

Ah.. if you're compiling C.. you MUST declare all your variables before doing anything else, so either move your "int g" to the very first line of the function, or choose C++ instead, which doesn't have this problem..

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

Post by midra » Wed May 26, 2004 4:59 am

WAW!! YOu are so fast!!haha
I suppouse that you write the msg. just when I send my reply!!
Thanks a lot!
but now I got WA!!!! :-?

Post Reply

Return to “Volume 4 (400-499)”