386 - Perfect Cubes
Moderator: Board moderators
-
- Learning poster
- Posts: 60
- Joined: Sun Apr 16, 2006 7:59 pm
Firstly, long int is equal to long. furthermore, long is machine dependent type, so in 32bit processors, it will be 32bit, and in 64bit, is 64bit.
But int is 32bit type. so In 32bit processor int and long has the same effect.
secondly, Please remove your code from this forum, although it is a very simple code, Thanks.
But int is 32bit type. so In 32bit processor int and long has the same effect.
secondly, Please remove your code from this forum, although it is a very simple code, Thanks.
-
- Learning poster
- Posts: 60
- Joined: Sun Apr 16, 2006 7:59 pm
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
386 - PE - I can't guess why ...
My program gets PE, so I suppose it is correct.
But anyone can explain me what I am doing wrong in writting output ?
This is a part of my program which writes data to output:
I got this from problem specification ...
Could anyone help me?
Best regards
DM
But anyone can explain me what I am doing wrong in writting output ?
This is a part of my program which writes data to output:
Code: Select all
while(i<counter)
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",results[i].a,
results[i].b,results[i].c,results[i].d);
i++;
}
Could anyone help me?
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
But in such case I should get WA instead of PE ![:)](./images/smilies/icon_smile.gif)
And because I got PE , not WA, I suppose that my program is correct
Best regards
DM
PS. Thanks![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
And because I got PE , not WA, I suppose that my program is correct
Best regards
DM
PS. Thanks
![:)](./images/smilies/icon_smile.gif)
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
386 - Perfect Cubes [WA]
I've compared the output using FC with some other's output and they match, can anybody tell what's going on?
Code: Select all
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstdlib>
using namespace std;
bool cubes[80000001]={false};
struct lc
{
int num;
int i, j, k;
} list[500]={0,0,0,0};
int cmp(const void *a, const void *b)
{
if (((struct lc*)a)->num != ((struct lc*)b)->num)
return (((struct lc*)a)->num - ((struct lc*)b)->num);
else
return (((struct lc*)a)->k - ((struct lc*)b)->k);
}
void cuber(int lim)
{
int i, j, k, l=0, x;
for (i=2 ; i<=lim ; i++)
{
cubes[i*i*i]=true;
}
for (i=2 ; i<=lim ; i++)
{
for (j=2 ; j<=i ; j++)
{
for (k=2 ; k<=j ; k++)
{
x = i*i*i + j*j*j + k*k*k;
if (cubes[x])
{
list[l].k=k;
list[l].j=j;
list[l].i=i;
list[l].num=pow((double)x,1.0/3.0)+1;
l++;
}
}
}
}
qsort(list,l,sizeof(struct lc),cmp);
for (i=0 ; i<l ; i++)
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",list[i].num,list[i].k,list[i].j,list[i].i);
}
}
int main()
{
freopen("minso.txt","w+",stdout);
cuber(200);
return 0;
}
Re: 386 - Perfect Cubes [WA]
what is the prblm with my cose???
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,d,pa,pb,pc,pd;
for(a=6;a<=200;a++)
{
pa=pow(a,3);
for(d=2;d<a;d++)
{
pd=pow(d,3);
for(c=d+1;c<a;c++)
{
pc=pow(c,3);
for(b=c+1;c<a;b++)
{
pb=pow(b,3);
if(pa==pb+pc+pd)
printf("Cube = %d, Triple = (%d,%d,%d)\n",a,d,c,b);
}
}
}
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 386 - Perfect Cubes [WA]
Line 15 should be changed from:
for(b=c+1;c<a;b++)
to:
for(b=c+1;b<a;b++)
for(b=c+1;c<a;b++)
to:
for(b=c+1;b<a;b++)
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 386 - Perfect Cubes [WA]
gtcoder, don't direct stdout to a file.
Check input and AC output for thousands of problems on uDebug!
Re: 386 - Perfect Cubes [WA]
thanks.... but still time limit... ![:(](./images/smilies/icon_frown.gif)
![:(](./images/smilies/icon_frown.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 386 - Perfect Cubes [WA]
On this problem you can generate the output on your machine and submit a code that just prints the output.
Check input and AC output for thousands of problems on uDebug!
Re: 386 - Perfect Cubes [WA]
I compared my output with an accepted output. It is the same. Still WA.
Code: Select all
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int cubes[201];
struct node
{
int d;
int a;
int b;
int c;
};
node obj(int x,int y,int z, int w)
{
node obj;
obj.d = x;
obj.a = y;
obj.b = z;
obj.c = w;
return obj;
}
void initialise()
{
for(int i = 0; i < 201;i++)
cubes[i] = i*i*i;
}
bool compare(node aa,node bb)
{
if(aa.d == bb.d)
{
if(aa.a == bb.a)
{
if(aa.b == bb.b)
{
return aa.c < bb.c;
}
return aa.b < bb.b;
}
return aa.a < bb.a;
}
return aa.d < bb.d;
}
int main()
{
initialise();
vector<node> triples;
for(int i = 1;i <= 200;i++)
{
for(int j = i;j <= 200; j++)
{
for(int k = j; k <= 200;k++)
{
int sum = cubes[i] + cubes[j] + cubes[k];
int m = k+1;
while(m < 201 && cubes[m] < sum)
m++;
if(m < 201 && cubes[m] == sum)
triples.push_back(obj(m,i,j,k));
}
}
}
sort(triples.begin(),triples.end(),compare);
for(int i =0;i < triples.size();i++)
printf("Cube = %d, Triple = (%d,%d,%d)\n",triples[i].d,triples[i].a,triples[i].b,triples[i].c);
return 0;
}