11428 - Cubes

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

Moderator: Board moderators

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 11428 - Cubes

Post by Obaida » Tue Jan 06, 2009 11:29 am

I don't know what's going on with me. Some one please help me to get ACC.
I got so many WA.

Code: Select all

removed
Last edited by Obaida on Wed Jan 07, 2009 7:36 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 11428 - Cubes

Post by Jan » Tue Jan 06, 2009 3:45 pm

Read the description please. 'If there is more than one solution then output the one with smallest value of y.'
I think you are maximizing y.
Ami ekhono shopno dekhi...
HomePage

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 11428 - Cubes

Post by Obaida » Wed Jan 07, 2009 7:36 am

Oh....
tomorrow i was kidding with my self.
Thank for fixing mistake. :)
try_try_try_try_&&&_try@try.com
This may be the address of success.

shafin.MIST
New poster
Posts: 1
Joined: Fri Oct 22, 2010 3:54 pm

Re: 11428 - Cubes

Post by shafin.MIST » Fri Oct 22, 2010 3:59 pm

What's the prb in this code!!!!!!!!!!! its freaking me off

Code: Select all

#include<stdio.h>
#include<string.h>
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	long int i,j,y,N;
	int digits[10005][2];
	for(i=1;i<100;i++)
		{
			for(j=1;j<i;j++)
			{
				y=i*i*i-j*j*j;
				if(y<=10000 && digits[y][0]<0)
				{
					digits[y][0]=i;
					digits[y][1]=j;
				}
			}
		}
	while(scanf("%ld",&N))
	{
		
		if(N==0)break;
		if(digits[N][0]>0)
			printf("%d %d\n",digits[N][0],digits[N][1]);
		else
			printf("No solution\n");
	}
	return 0;
}

santosh
New poster
Posts: 2
Joined: Thu Apr 14, 2011 2:57 pm

Re: 11428 - Cubes

Post by santosh » Thu Apr 14, 2011 3:07 pm

#include<stdio.h>
#include<math.h>

int main()
{
int flag , j , k , k1 ;
int i , temp , temp1 ;
int a[50] , b[50] ;

for(j=0 ; j<50 ; j++)
a[j] = pow(j , 3) ;

while( scanf("%d" , &i ) == 1 )
{
if( i == 0 )
break ;

for(j=0 ; j<50 ; j++)
b[j] = 0 ;

k=0 ;
for(j=0 ; j<50 ; j++)
{
if( a[j] <= i )
b[k++] = a[j] + i ;
else if( i > a[j] )
break ;
}


flag=0 ;
k=0 ;
for(j=0 ; j<50 ; j++)
{
for(k1=0 ; k1<50 ; k1++)
{
if( b[k1] == a[j] )
{
temp = j ;
flag = 1 ;
break ;
}
}
}

temp1 = a[temp] - i ;

for(j=0 ; j<50 ; j++)
{
if( a[j] == temp1 )
{
temp1 = j ;
break ;
}
}

if( flag == 1 && temp > temp1 && temp1 >= 0 )
printf("%d %d\n" , temp , temp1 ) ;
else
printf("No solution\n") ;
}
return 0 ;
}
[quote][/quote] can anyone give me speial test case???find any bug???

Gabrielwer
New poster
Posts: 6
Joined: Thu Sep 08, 2011 12:27 pm

Re: 11428 - Cubes

Post by Gabrielwer » Fri Sep 09, 2011 3:26 pm

Thanx for the codes!!cell phone tracking it's highly appreciated :DI’ve manipulated the code and I’m using it to help others. I hope that is fine ;D

arif.cse28
New poster
Posts: 1
Joined: Sun Jul 31, 2011 5:43 pm

11428 wa.ahy?

Post by arif.cse28 » Fri Sep 16, 2011 12:36 pm

some1 tell me the bugs.why it is showing WA?

Code: Select all

// id 11428

#include <stdio.h>

int main()
{
	long int x[50],y[50],n,temp_i,temp_x,temp_1;
	int i,j,flag;
	
	for(i=0; i<50; i++)
	{
		x[i]=i*i*i;
		y[i]=i*i*i;
	}
	while(1)
	{
		scanf("%ld",&n);
		flag=0;
		
		if(n==0)
		{
			break;
		}
		
		i=0;
		while(x[i]<=n)
		{
			i++;
		}		
		temp_i=i;
		
		temp_x=x[i];
		
		
		for(j=0; j<temp_i; j++)
		{
			//temp_1=n+y[j];
			
			
			if(n+y[j]==temp_x)
			{
				
				flag=1;
				break;
			}
			
		}
		if(flag)
		{
			printf("%ld %d\n",temp_i,j);
		}
		else
		{
			printf("No solution\n");
	    }
	}
return 0;
}

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

11428 - Cubes (about 7 times TLE and 3 times WA)

Post by uvasarker » Fri Dec 02, 2011 3:36 pm

Anyone help me please, why WA?
Here is my code (WA):

Code: Select all

#include <cstdio>
#include <cmath>
int main()
{
	int n;
	//freopen("in_11428.txt","r",stdin);
	//freopen("out_11428.txt","w",stdout);
	while(scanf("%d",&n)==1)
	{
		int i,j,flag=0,m,k;
		int num,x3,y3;
		if (n==0) break;
		
		for(i=1;i<=(sqrt(n)/2)+1;i++)
		{
			x3=i*i*i;
			if(x3<n) continue;
			for(j=1;j<=(sqrt(n)/2)+1;j++)
			{
				y3=j*j*j;
				if(y3>x3) continue;
				num=x3-y3;
				if(num==n)
				{
					m=i;
					k=j;
					flag=1;
					break;
				}
				else if(num>n)
				{
					continue;
				}
			}
		}
		if(flag==1)
			printf("%d %d\n",m,k);
		else
			printf("No solution\n");
	}
	return 0;
}

Last edited by uvasarker on Fri Jan 13, 2012 6:35 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

Post by brianfry713 » Fri Jan 13, 2012 2:48 am

Your code is currently giving WA, not anywhere close to TLE.

For N=397, my AC code prints "12 11". Yours prints "No solution".
Check input and AC output for thousands of problems on uDebug!

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

Post by uvasarker » Fri Jan 13, 2012 6:59 am

Hi,
brianfry713
thanks for your suggestions. Please, give more critical test cases. STILL WA.
Here is my modified code

Code: Select all

#include <cstdio>
#include <cmath>
int main()
{
	long n;
	//freopen("in_11428.txt","r",stdin);
	//freopen("out_11428.txt","w",stdout);
	while(scanf("%ld",&n)==1)
	{
		long i,j,flag=0,m,k;
		long num,x3,y3;
		if (n==0) break;
		
		for(i=1 ; i<=(int)sqrt(n)+10 ; i++)
		{
			x3=i*i*i;
			for(j=1 ; j<=i ; j++)
			{
				y3=j*j*j;
//				printf("%ld %ld\n",x3,y3);
				if(y3>x3) continue;
				num=x3-y3;
				if(num==n)
				{
					m=i;
					k=j;
					flag=1;
					break;
				}
				else if(num>n)
				{
					continue;
				}
			}
		}
		if(flag==1)
			printf("%ld %ld\n",m,k);
		else
			printf("No solution\n");
	}
	return 0;
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

Post by brianfry713 » Fri Jan 13, 2012 10:26 pm

N=721, my AC code prints "9 2", your modified code "16 15". If there is more than one solution then output the one with smallest value of y.
Check input and AC output for thousands of problems on uDebug!

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

Post by uvasarker » Sat Feb 11, 2012 5:52 am

Thanks a lot.
Thanks a lot boss.
Finally I got it AACC.

sadia_atique
New poster
Posts: 25
Joined: Thu Nov 24, 2011 6:32 am

Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

Post by sadia_atique » Tue Feb 14, 2012 7:22 pm

Getting WA in this problem,can anyone help please?any special case I've missed?

Code: Select all

#include<stdio.h>
typedef struct{
        int x;
        int y;
        }s;
s cube[20005];
int main()
{
    int i,j,k,p;
    for(i=0; i<=22; i++)
    {
             for(j=i+1; j<=22; j++)
             {
                      p=(j*j*j)-(i*i*i);
                      if(cube[p].x==0 && cube[p].y==0)
                      {
                      cube[p].x=j;
                      cube[p].y=i;
                      }
                      else
                      {
                          if(cube[p].y>i)
                          {
                               cube[p].x=j;
                               cube[p].y=i;
                               }
                          }
                              
                      }
             }
    int n;
    while(scanf("%d",&n)==1 && n!=0)
    {
         if(cube[n].x==0 && cube[n].y==0) printf("No solution\n");
         else printf("%d %d\n",cube[n].x,cube[n].y);
         }
    return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

Post by brianfry713 » Wed Feb 15, 2012 12:04 am

N=1 is "No solution", y must be positive, not zero.
Check input and AC output for thousands of problems on uDebug!

sadia_atique
New poster
Posts: 25
Joined: Thu Nov 24, 2011 6:32 am

Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

Post by sadia_atique » Wed Feb 15, 2012 8:33 am

I've changed that part,started the loop from i=1,so y and x both will be always>0,it still gives WA :cry:

Post Reply

Return to “Volume 114 (11400-11499)”