386 - Perfect Cubes

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

Moderator: Board moderators

dumb dan
Learning poster
Posts: 67
Joined: Tue Aug 05, 2003 1:02 am

Post by dumb dan »

I don't know why you'd get WA, I would have expected you to get TLE though. You definately want to use ints instead of long ints.

Besides this, there are very simple means by which your solution can be made more efficient.
ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi »

hi there!
anyway,i got accepted .....
made a silly mistake in the spelling of "Triple"..
thanks a lot.....
Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha »

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.
ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi »

hello all.....
thanks a lot.......
thanks for ur help & for ur time....
.........
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

386 - PE - I can't guess why ...

Post by Dominik Michniewski »

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:

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++;
}
I got this from problem specification ...

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)
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

I can't find anything wrong with your output format...

Other possiblities is your not ouputing with specified order.
Be sure that b <= c <= d , and for same a, smaller b triple must be printed first.

----
Sory for my poor English.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

But in such case I should get WA instead of PE :)

And because I got PE , not WA, I suppose that my program is correct

Best regards
DM

PS. Thanks :)
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)
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

I don't have any clue ..

If you don't matter, send me your code with private message.
Maybe I could find out.
gtcoder
New poster
Posts: 12
Joined: Tue Mar 23, 2010 5:45 am

386 - Perfect Cubes [WA]

Post by gtcoder »

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;
}
shoaib7k
New poster
Posts: 10
Joined: Thu Aug 18, 2011 7:45 pm

Re: 386 - Perfect Cubes [WA]

Post by shoaib7k »

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;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 386 - Perfect Cubes [WA]

Post by brianfry713 »

Line 15 should be changed from:
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!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 386 - Perfect Cubes [WA]

Post by brianfry713 »

gtcoder, don't direct stdout to a file.
Check input and AC output for thousands of problems on uDebug!
shoaib7k
New poster
Posts: 10
Joined: Thu Aug 18, 2011 7:45 pm

Re: 386 - Perfect Cubes [WA]

Post by shoaib7k »

thanks.... but still time limit... :(
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 386 - Perfect Cubes [WA]

Post by brianfry713 »

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!
mathgirl
New poster
Posts: 36
Joined: Tue Apr 24, 2012 6:20 pm

Re: 386 - Perfect Cubes [WA]

Post by mathgirl »

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;
}
Post Reply

Return to “Volume 3 (300-399)”