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

titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

Post by titid_gede » Tue Feb 03, 2004 10:24 am

i submitted your code without any changes and got AC. so what's your problem?

-titid-
Kalo mau kaya, buat apa sekolah?

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR » Tue Feb 03, 2004 11:21 am

My problem is that the OJ returns WA!!!

If the code is ok, then what could be the reason for this?

It compiles ok so it can't be the mail program.

I will just submit the code again and see what happens this time.

Thanks for the 2nd time today!!!

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR » Tue Feb 03, 2004 1:25 pm

Hi titid,

Well it's a WA again!!!
Your program has not solved the problem. It ran during 1.273 seconds.
I didn't change anything.

How come you got the program accepted?

titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

Post by titid_gede » Tue Feb 03, 2004 1:52 pm

how did u submit it? using yahoo mail? or using what? try using submit o matic :D :D :D
Kalo mau kaya, buat apa sekolah?

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR » Tue Feb 03, 2004 2:43 pm

Ok, I used submit-o-matic and the statistics show that the
program now has been accepted!

So indeed the mail program has been the culprit.

Switching to submit-o-matic from now on!

Thanks again titid!

Sarwar
New poster
Posts: 3
Joined: Tue Nov 04, 2003 12:20 pm
Location: Dhaka

Post by Sarwar » Mon Jun 14, 2004 4:59 pm

I am getting worng answer. where is the problem??
please help me.........

[cpp]

#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX 100

long DEC;
char Other[MAX];

char Insert_Char(long base,long mod)
{
long i;
char C = 'A';

for(i = 0; i < base - 10; i++)
if(mod == 10+i) return (char) (C+i);

return '0';

}

void To_Desimal(char *NUM, long base)
{
long i,ins,l,len;

l = len = strlen(NUM) - 1;
DEC = 0;
for(i = 0; i <= len ; i++)
{
if(NUM == 'A') ins = 10;
else if( NUM == 'B') ins = 11;
else if( NUM == 'C') ins = 12;
else if( NUM == 'D') ins = 13;
else if( NUM == 'E') ins = 14;
else if( NUM == 'F') ins = 15;
else ins = NUM - '0';

DEC = DEC + ins * pow(base,l);
l--;
}
}

void From_Desimal(long base)
{
long i,mod,len,j;
char temp[MAX];
long dec;
dec = DEC;

for(i = 0; dec!=0;i++ )
{
mod = dec % base;

if(mod >= 10)
temp = Insert_Char(base,mod);


else temp = mod + '0';

dec = dec / base;
}
temp = NULL;

len = strlen(temp)-1;
j = 0;
for(i = len; i >= 0; i-- )
Other[j++]=temp[i];

Other[j] = NULL;


}


int main()
{

int i,minus;
long b1,b2,flag;
char NUM[MAX];

//freopen("c:\\out.txt","w",stdout);

while( scanf("%s %ld%ld",NUM,&b1,&b2)==3)
{
flag = 0;
minus = 0;

for(i = 0; NUM[i]!=NULL; i++)
if(NUM[i] != '0'){ flag=1;break;}


if(flag == 0) {printf(" 0\n");continue;}

else if(b2 == 10 )
{

To_Desimal(NUM,b1);
if(DEC > 9999999){printf(" ERROR\n");continue;}
printf("%7lld\n",DEC);
}

else if(b1 == 10)
{
sscanf(NUM,"%lld",&DEC);
From_Desimal(b2);
if(strlen(Other) > 7){ printf(" ERROR\n");continue;}
printf("%7s\n",Other);
}
else
{

To_Desimal(NUM,b1);
From_Desimal(b2);
if(strlen(Other) > 7){printf(" ERROR\n");continue;}
printf("%7s\n",Other);
}

}

return 0;
}

[/cpp]

User avatar
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 » Mon Jun 14, 2004 5:48 pm

There is no input for this problem. You are to find and output all sets with a <= 200.

randomtaiwanese
New poster
Posts: 32
Joined: Fri Oct 01, 2004 10:53 pm

386 what is wrong

Post by randomtaiwanese » Thu Nov 18, 2004 6:55 am

[java]for(int i=6;i<=200;i++)
{
for(int j=2;j<i;j++)
{
for(int k=2;k<=j;k++)
{
for(int l=2;l<=k;l++)
{
if(i*i*i==(k*k*k+j*j*j+l*l*l))
{
System.out.println("Cube = "+i+", Triple = ("+l+","+k+","+j+")");
}
}
}
}
}[/java]

rajeshr92
New poster
Posts: 1
Joined: Tue Apr 19, 2005 1:42 pm

Getting 0:00 time for problem 386

Post by rajeshr92 » Tue Apr 19, 2005 1:47 pm

I would like to know how get 00:00 time for problem 386.I used the following code and
got time of 0:01:614.Though it got AC i would like to optimize more


#include <stdio.h>
int main()
{
int a,b,c,d;
for(a=6;a<=200;a++)
for(b=2;b<a;b++)
for(c=b;c<a;c++)
for(d=c;d<a;d++)
if(a*a*a==(b*b*b+c*c*c+d*d*d))
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
}
return 0;
}

User avatar
sahand
New poster
Posts: 19
Joined: Sat Mar 12, 2005 5:56 pm
Location: Halifax, Nova Scotia, Canada
Contact:

Post by sahand » Fri Apr 29, 2005 6:16 pm

Hi,

I think most of those 0:00 for this problem are done using pre calculation.
Maybe even all of them!
Anyway, I think you can optimize your code a good amount in the following way. I could get it accepted in 0:00.980 which is not really good, but is still better.

Code: Select all

#include <stdio.h>

int main()
{
	int a,b,c,d;
	int acube,bcube,ccube,bplusc;
	for(a=6;a<=200;a++)
	{
		acube=a*a*a;
		for(b=2;b<a;b++)
		{
			bcube=b*b*b;
			for(c=b;c<a;c++)
			{
				ccube=c*c*c;
				bplusc=bcube+ccube;
				for(d=c;d<a;d++)
				{
					if(acube==(bplusc+d*d*d))
					{
						printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
					}
				}
			}
		}		
	}
	return 0;
}

Md. Aftabuddin
New poster
Posts: 3
Joined: Sun Jun 26, 2005 2:24 pm

The judgieing machine seems wrong

Post by Md. Aftabuddin » Sun Jun 26, 2005 2:47 pm

Dear Sir,
I am a new commer I solved the question no 386 and submitted only to get wrong answer.
But my solution is right and running within the time limit. Further more the output given in the question is itself wrong. it is not showing the line

Cube = 9, Triple = (1,6,8 )

but 9*9*9=1*1*1 +6*6*6+ 8*8*8

So the question must be corrected.
I also submitted question no 834 but your judging system says it as wrong.

Also I took part in the online programming contest on 25/6/2005 I solved the question B only but your online judge says it as wrong answer .
There must be some thing wrong in the judgeing system


Md. Aftabuddin
Last edited by Md. Aftabuddin on Tue Jun 28, 2005 4:57 pm, edited 1 time in total.

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel » Sun Jun 26, 2005 3:21 pm

Please make sure that you understand the problem. I believe you that you think you solved the problems right, however you will always get WA if you solved another problem than was posed.
For problem 386, please consider that you have to find values a,b,c > 1 !!!
I suggest you read the problem descriptions of that other problems again, maybe you also overlooked something.

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post by misof » Mon Jun 27, 2005 11:59 am

Also, it is not wise to post your whole ID, you are supposed to keep the two letters at the end secret. (Anyone that knows them may submit solutions using your account.) I suggest that you edit your post and delete them before anyone can misuse this information.

alexg
New poster
Posts: 5
Joined: Wed Sep 01, 2004 11:24 am
Location: London, UK

Post by alexg » Thu May 04, 2006 3:28 pm

I got 0.018 by using a hash table. I'll leave you to work out how a hashtable could help in this situation.

ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

386 wa, it seems ok but......

Post by ayeshapakhi » Mon May 29, 2006 7:56 pm

please show me the mistake...
thanks.........

Code: Select all

the code is removed.
Last edited by ayeshapakhi on Wed May 31, 2006 7:00 am, edited 1 time in total.

Post Reply

Return to “Volume 3 (300-399)”