386  Perfect Cubes
Moderator: Board moderators
386 so simple BUT...
my program gives me 216 lines of output and
it gives me WA
how many output lines it should be ?????
the sorting method is based ascending value of
"b" right??
it gives me WA
how many output lines it should be ?????
the sorting method is based ascending value of
"b" right??
386  keep getting wrong answer
My program has 223 lines of output, and the first ones are exactly the same as in the problem set, but I keep getting wrong answer. Does anyone know what could be wrong?

 New poster
 Posts: 38
 Joined: Mon Dec 09, 2002 1:53 pm
 Location: Poznan, Poland
Re: 386 so simple BUT...
I compiled it and it printed 223 line on my computer.Rong wrote:Why does give 222 lines in my output ?
This isn't verry efficient. You should check using math functions if exists a such integer d that a^3b^3c^3=d^3Rong wrote: [cpp]
for(d=c;d<a;d++)
{
if(i==(pow(b,3)+pow(c,3)+pow(d,3)))
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
break;
}
}
}[/cpp]

 New poster
 Posts: 38
 Joined: Mon Dec 09, 2002 1:53 pm
 Location: Poznan, Poland

 New poster
 Posts: 38
 Joined: Thu Dec 11, 2003 3:40 pm
 Location: Bangalore
386  Perfect Cubes
What is wrong with this code plz help.. i thought this was a cool logic but got wa....
It seems to work and gives me 223 answers.. Plz help...
Plzz help
[cpp]
# include<iostream.h>
long a;
long init,temp;
int i,j1,j2,j3;
long cube[201];
long sol[300][3];
long sc;
int find(int x,int y,int z)
{
for(int i=0;i<sc;i++)
if((sol[0]==x && sol[1]==y && sol[2]==z)  (sol[0]==x && sol[2]==y && sol[1]==z) (sol[2]==x && sol[1]==y && sol[0]==z)  (sol[2]==x && sol[i][0]==y && sol[i][1]==z) (sol[i][1]==x && sol[i][2]==y && sol[i][0]==z)  (sol[i][1]==x && sol[i][0]==y && sol[i][2]==z)) return 1;
return 0;
}
int main()
{
sc=0;
a=1;
init=7;
temp=6;
for(i=1;i<=200;i++)
{
cube[i]=a;
//cout<<a<<",\n";
a+=init;
temp+=6;
init+=temp;
}
for(i=6;i<=200;i++)
{
//cout<<cube[i]<<"\n";
for(j1=2;j1<=i3;j1++)
{
for(j2=j1+1;j2<=i2;j2++)
{
for(j3=j2+1;j3<=i1;j3++)
{
if(cube[i]==cube[j1]+cube[j2]+cube[j3])
{
if(find(j1,j2,j3)==0)
{
sol[sc][0]=j1;sol[sc][1]=j2;sol[sc][2]=j3;sc++;
cout<<"Cube = "<<i<<", Triple = ("<<j1<<","<<j2<<","<<j3<<")\n";
}
}
}
}
}
}
return 1;
}
//@end_of_source_code
[/cpp]
It seems to work and gives me 223 answers.. Plz help...
Plzz help
[cpp]
# include<iostream.h>
long a;
long init,temp;
int i,j1,j2,j3;
long cube[201];
long sol[300][3];
long sc;
int find(int x,int y,int z)
{
for(int i=0;i<sc;i++)
if((sol[0]==x && sol[1]==y && sol[2]==z)  (sol[0]==x && sol[2]==y && sol[1]==z) (sol[2]==x && sol[1]==y && sol[0]==z)  (sol[2]==x && sol[i][0]==y && sol[i][1]==z) (sol[i][1]==x && sol[i][2]==y && sol[i][0]==z)  (sol[i][1]==x && sol[i][0]==y && sol[i][2]==z)) return 1;
return 0;
}
int main()
{
sc=0;
a=1;
init=7;
temp=6;
for(i=1;i<=200;i++)
{
cube[i]=a;
//cout<<a<<",\n";
a+=init;
temp+=6;
init+=temp;
}
for(i=6;i<=200;i++)
{
//cout<<cube[i]<<"\n";
for(j1=2;j1<=i3;j1++)
{
for(j2=j1+1;j2<=i2;j2++)
{
for(j3=j2+1;j3<=i1;j3++)
{
if(cube[i]==cube[j1]+cube[j2]+cube[j3])
{
if(find(j1,j2,j3)==0)
{
sol[sc][0]=j1;sol[sc][1]=j2;sol[sc][2]=j3;sc++;
cout<<"Cube = "<<i<<", Triple = ("<<j1<<","<<j2<<","<<j3<<")\n";
}
}
}
}
}
}
return 1;
}
//@end_of_source_code
[/cpp]
Last edited by aakash_mandhar on Mon Jan 05, 2004 12:48 am, edited 1 time in total.
...I was born to code...
Nothing is wrong.
I have gone through your code and found no mistakes in it. So I decided to submit it and was not surprised to see 'accepted' as the reply. It means yours was a cool logic.

 New poster
 Posts: 38
 Joined: Thu Dec 11, 2003 3:40 pm
 Location: Bangalore
AC
Thx for the help..
I have removed my id from the post..
Thx again
Glad you liked the logic.
I have removed my id from the post..
Thx again
Glad you liked the logic.
...I was born to code...
WA 386
Hi,
using brute force (or ''complete enumeration'' as I prefer to call it)
I get 223 lines of output  but a WA.
Summarizing the rules:
1) sort by nondescending a
2) b <= c <= d
3) if there's more than one triple for a specific a,
sort by the value of b (ascending)
Example:
Cube = 150, Triple = (24,102,132)
Cube = 150, Triple = (71,73,138)
Cube = 150, Triple = (75,100,125)
Cube = 150, Triple = (76,86,132)
So what's my mistake?!
Any hints?
using brute force (or ''complete enumeration'' as I prefer to call it)
I get 223 lines of output  but a WA.
Summarizing the rules:
1) sort by nondescending a
2) b <= c <= d
3) if there's more than one triple for a specific a,
sort by the value of b (ascending)
Example:
Cube = 150, Triple = (24,102,132)
Cube = 150, Triple = (71,73,138)
Cube = 150, Triple = (75,100,125)
Cube = 150, Triple = (76,86,132)
So what's my mistake?!
Any hints?

 Learning poster
 Posts: 57
 Joined: Wed Dec 10, 2003 7:32 pm
 Location: Russia, SaintPetersburg
First outputs for this problem:
[pascal]program acm386; {a^3=b^3+c^3+d^3}
begin
writeln('Cube = 6, Triple = (3,4,5)');
writeln('Cube = 12, Triple = (6,8,10)');
writeln('Cube = 18, Triple = (2,12,16)');
writeln('Cube = 18, Triple = (9,12,15)');
writeln('Cube = 19, Triple = (3,10,18)');
writeln('Cube = 20, Triple = (7,14,17)');
writeln('Cube = 24, Triple = (12,16,20)');
writeln('Cube = 25, Triple = (4,17,22)');
writeln('Cube = 27, Triple = (3,18,24)');
writeln('Cube = 28, Triple = (18,19,21)');
writeln('Cube = 29, Triple = (11,15,27)');
writeln('Cube = 30, Triple = (15,20,25)');
writeln('Cube = 36, Triple = (4,24,32)');
writeln('Cube = 36, Triple = (18,24,30)');
[/pascal]
I hope it helps you.
[pascal]program acm386; {a^3=b^3+c^3+d^3}
begin
writeln('Cube = 6, Triple = (3,4,5)');
writeln('Cube = 12, Triple = (6,8,10)');
writeln('Cube = 18, Triple = (2,12,16)');
writeln('Cube = 18, Triple = (9,12,15)');
writeln('Cube = 19, Triple = (3,10,18)');
writeln('Cube = 20, Triple = (7,14,17)');
writeln('Cube = 24, Triple = (12,16,20)');
writeln('Cube = 25, Triple = (4,17,22)');
writeln('Cube = 27, Triple = (3,18,24)');
writeln('Cube = 28, Triple = (18,19,21)');
writeln('Cube = 29, Triple = (11,15,27)');
writeln('Cube = 30, Triple = (15,20,25)');
writeln('Cube = 36, Triple = (4,24,32)');
writeln('Cube = 36, Triple = (18,24,30)');
[/pascal]
I hope it helps you.
Thanks for the post pavelph,
but it doesn't help because my output is exactly the same.
but it doesn't help because my output is exactly the same.
Code: Select all
#include <stdio.h> /* printf */
/*****************************
* ACM Contest  Problem 386 *
*****************************/
int main(void)
{
const int max = 200;
long a, b, c, d;
long a3, b3, c3, d3;
for (a=2;a<=max;a++){
a3 = a*a*a;
for (b=2;b<=a;b++){
b3 = b*b*b;
for (c=b;c<=a;c++){
c3 = c*c*c;
for (d=c;d<=a;d++){
d3 = d*d*d;
if (b3+c3+d3 == a3)
printf("Cube = %ld, Triple = (%ld,%ld,%ld)\n",a,b,c,d);
}
}
}
}
return 0;
}