Page 2 of 5

Re: 11428 - Cubes

Posted: Tue Jan 06, 2009 11:29 am
by Obaida
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

Re: 11428 - Cubes

Posted: Tue Jan 06, 2009 3:45 pm
by Jan
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.

Re: 11428 - Cubes

Posted: Wed Jan 07, 2009 7:36 am
by Obaida
Oh....
tomorrow i was kidding with my self.
Thank for fixing mistake. :)

Re: 11428 - Cubes

Posted: Fri Oct 22, 2010 3:59 pm
by shafin.MIST
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;
}

Re: 11428 - Cubes

Posted: Thu Apr 14, 2011 3:07 pm
by santosh
#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???

Re: 11428 - Cubes

Posted: Fri Sep 09, 2011 3:26 pm
by Gabrielwer
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

11428 wa.ahy?

Posted: Fri Sep 16, 2011 12:36 pm
by arif.cse28
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;
}

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

Posted: Fri Dec 02, 2011 3:36 pm
by uvasarker
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;
}


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

Posted: Fri Jan 13, 2012 2:48 am
by brianfry713
Your code is currently giving WA, not anywhere close to TLE.

For N=397, my AC code prints "12 11". Yours prints "No solution".

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

Posted: Fri Jan 13, 2012 6:59 am
by uvasarker
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;
}


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

Posted: Fri Jan 13, 2012 10:26 pm
by brianfry713
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.

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

Posted: Sat Feb 11, 2012 5:52 am
by uvasarker
Thanks a lot.
Thanks a lot boss.
Finally I got it AACC.

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

Posted: Tue Feb 14, 2012 7:22 pm
by sadia_atique
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;
}

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

Posted: Wed Feb 15, 2012 12:04 am
by brianfry713
N=1 is "No solution", y must be positive, not zero.

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

Posted: Wed Feb 15, 2012 8:33 am
by sadia_atique
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: