Page 3 of 4

Posted: Tue May 30, 2006 2:30 pm
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.

Posted: Tue May 30, 2006 2:53 pm
by ayeshapakhi
hi there!
anyway,i got accepted .....
made a silly mistake in the spelling of "Triple"..
thanks a lot.....

Posted: Tue May 30, 2006 11:37 pm
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.

Posted: Wed May 31, 2006 7:02 am
by ayeshapakhi
hello all.....
thanks a lot.......
thanks for ur help & for ur time....
.........

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

Posted: Sat Feb 10, 2007 10:30 am
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

Posted: Sat Feb 10, 2007 12:42 pm
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.

Posted: Sat Feb 10, 2007 2:51 pm
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 :)

Posted: Sat Feb 10, 2007 3:05 pm
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.

386 - Perfect Cubes [WA]

Posted: Wed Aug 03, 2011 2:02 am
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;
}

Re: 386 - Perfect Cubes [WA]

Posted: Mon Mar 19, 2012 6:08 pm
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;
}

Re: 386 - Perfect Cubes [WA]

Posted: Mon Mar 19, 2012 10:32 pm
by brianfry713
Line 15 should be changed from:
for(b=c+1;c<a;b++)
to:
for(b=c+1;b<a;b++)

Re: 386 - Perfect Cubes [WA]

Posted: Mon Mar 19, 2012 10:41 pm
by brianfry713
gtcoder, don't direct stdout to a file.

Re: 386 - Perfect Cubes [WA]

Posted: Tue Mar 20, 2012 10:57 am
by shoaib7k
thanks.... but still time limit... :(

Re: 386 - Perfect Cubes [WA]

Posted: Tue Mar 20, 2012 9:24 pm
by brianfry713
On this problem you can generate the output on your machine and submit a code that just prints the output.

Re: 386 - Perfect Cubes [WA]

Posted: Thu May 31, 2012 1:08 pm
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;
}