All about problems in Volume III. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
by gtcoder » Wed Aug 03, 2011 2:02 am
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;
}
-
gtcoder
- New poster
-
- Posts: 12
- Joined: Tue Mar 23, 2010 5:45 am
by shoaib7k » Mon Mar 19, 2012 6:08 pm
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;
}
-
shoaib7k
- New poster
-
- Posts: 10
- Joined: Thu Aug 18, 2011 7:45 pm
by brianfry713 » Mon Mar 19, 2012 10:32 pm
Line 15 should be changed from:
for(b=c+1;c<a;b++)
to:
for(b=c+1;b<a;b++)
-
brianfry713
- Guru
-
- Posts: 1765
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
by brianfry713 » Mon Mar 19, 2012 10:41 pm
gtcoder, don't direct stdout to a file.
-
brianfry713
- Guru
-
- Posts: 1765
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
by shoaib7k » Tue Mar 20, 2012 10:57 am
thanks.... but still time limit...

-
shoaib7k
- New poster
-
- Posts: 10
- Joined: Thu Aug 18, 2011 7:45 pm
by brianfry713 » Tue Mar 20, 2012 9:24 pm
On this problem you can generate the output on your machine and submit a code that just prints the output.
-
brianfry713
- Guru
-
- Posts: 1765
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
by mathgirl » Thu May 31, 2012 1:08 pm
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;
}
-
mathgirl
- New poster
-
- Posts: 36
- Joined: Tue Apr 24, 2012 6:20 pm
by brianfry713 » Fri Jun 01, 2012 12:26 am
Your code is printing a line with a=9 and has other errors.
-
brianfry713
- Guru
-
- Posts: 1765
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
by mathgirl » Fri Jun 01, 2012 6:25 am
Ah!. My mistake. I did not see that a,b,c > 1. I changed the starting value to 2 and got AC.
-
mathgirl
- New poster
-
- Posts: 36
- Joined: Tue Apr 24, 2012 6:20 pm
Return to Volume III
Who is online
Users browsing this forum: No registered users and 1 guest