11428 - Cubes
Moderator: Board moderators
Re: 11428 - Cubes
Hi brianfry, for 631 my output is 15 14
Many of life’s failures are people who did not realize how close they were to success when they gave up.
Re: 11428-I am tired getting WA again& again
Sorry
Many of life’s failures are people who did not realize how close they were to success when they gave up.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11428 - Cubes
Your code has precision errors. When N = 631 and i = 14, on my system c = 14 and t = 0. The cuberoot of 3375 is exactly 15. Casting a double to an int is dangerous without adding a small value like 1e-8.
Check input and AC output for thousands of problems on uDebug!
Re: 11428 - Cubes
i add 0.0003 with the double value. but i am still getting WA. i have also tried with float. i tested my code for all the values from 1 t0 10000.plz,brianfry..tell me if the algorithm is ok! if its not then why?! and how can i improve this?
after adding 0.003 here is my new code-
plz help me
[removed]
after adding 0.003 here is my new code-
plz help me
[removed]
Last edited by X123 on Fri Nov 15, 2013 7:52 pm, edited 1 time in total.
Many of life’s failures are people who did not realize how close they were to success when they gave up.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11428 - Cubes
Your code is AC in C++. In C, it's always printing No solution. You could also try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!
Re: 11428 - Cubes
thanx brianfry ..thanx a lot.is the cuberoot the cause?
Many of life’s failures are people who did not realize how close they were to success when they gave up.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11428 - Cubes
Yes, cbrt() is not part of ANSI C, it is returning 1.0 with any argument.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 16
- Joined: Sun Nov 10, 2013 7:41 pm
11428 - Cubes why WA?????
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int a, b ,c, n;
long x;
while(cin>>n)
{
bool z=false;
if(n==0) break;
if(n==1)
{
cout<<"1 0\n";
continue;
}
for(a=1; a*a<n; a++)
{
x=a*a*a;
if(x==n)
{
cout<<a<<" 0\n";
z=true;
}
if(x>n)
{
for(b=1; b<a; b++)
{
long y=b*b*b;
if(x-y==n)
{
cout<<a<<" "<<b<<"\n";
z=true;
break;
}
}
}
}
if(z==false)
cout<<"No solution\n";
}
return 0;
}
#include <vector>
using namespace std;
int main()
{
int a, b ,c, n;
long x;
while(cin>>n)
{
bool z=false;
if(n==0) break;
if(n==1)
{
cout<<"1 0\n";
continue;
}
for(a=1; a*a<n; a++)
{
x=a*a*a;
if(x==n)
{
cout<<a<<" 0\n";
z=true;
}
if(x>n)
{
for(b=1; b<a; b++)
{
long y=b*b*b;
if(x-y==n)
{
cout<<a<<" "<<b<<"\n";
z=true;
break;
}
}
}
}
if(z==false)
cout<<"No solution\n";
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11428 - Cubes
Next time post in the existing thread. Input 1, AC output No solution
Check input and AC output for thousands of problems on uDebug!
Re: 11428 - Cubes
Each of these lines contains two positive integers x, y separated by a single space, such that
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- New poster
- Posts: 16
- Joined: Sun Nov 10, 2013 7:41 pm
Re: 11428 - Cubes
brianfry713 wrote:Next time post in the existing thread. Input 1, AC output No solution
Input 1, AC output No solution???
i dont understand :p
but i think for which case output could be 2 set or more this code printing all of them causing the ERROR.....
Re: 11428 - Cubes
Input
Acc output
Your output
Both x, y must be positive.
Code: Select all
1
8
0
Code: Select all
No solution
No solution
Code: Select all
1 0
2 0
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 11428 - Cubes
i am getting WA but i got accurate answer using http://www.udebug.com/UVa/11428 output:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int num;
int arr[100];
int a,b;
// freopen("text.txt","r",stdin);
while(scanf("%d",&num)==1)
{
if(num==0) break;
int flag=0;
if(num==1) printf("1 0\n");
else {
for(int i=0;i<=sqrt(num);i++)
{
arr=i;
}
for(int i=0;i<sqrt(num);i++)
{
for(int j=i+1;j<sqrt(num);j++)
{
if(((arr[j]*arr[j]*arr[j])-(arr*arr*arr))==num)
{
a=arr[j];
b=arr;
flag=1;
break;
}
}
}
if(flag==1) printf("%d %d\n",a,b);
else printf("No solution\n");
}
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int num;
int arr[100];
int a,b;
// freopen("text.txt","r",stdin);
while(scanf("%d",&num)==1)
{
if(num==0) break;
int flag=0;
if(num==1) printf("1 0\n");
else {
for(int i=0;i<=sqrt(num);i++)
{
arr=i;
}
for(int i=0;i<sqrt(num);i++)
{
for(int j=i+1;j<sqrt(num);j++)
{
if(((arr[j]*arr[j]*arr[j])-(arr*arr*arr))==num)
{
a=arr[j];
b=arr;
flag=1;
break;
}
}
}
if(flag==1) printf("%d %d\n",a,b);
else printf("No solution\n");
}
}
return 0;
}
Re: 11428 - Cubes
Use code tags.
Input
Output
It will be good if you remove all your codes after getting accepted.

Input
Code: Select all
8
721
728
999
3367
5768
5824
7992
0
Code: Select all
No solution
9 2
9 1
10 1
15 2
18 4
18 2
20 2
According to problem descriptionshaficse wrote:i am getting WA but i got accurate answer using http://www.udebug.com/UVa/11428 output:
Maybe Judge doesn't have input when N = x^3.Each of these lines contains two positive integers x, y separated by a single space, such that N = x^3 - y^3.
It will be good if you remove all your codes after getting accepted.

A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11428 - Cubes
try solving it without using floating point
Check input and AC output for thousands of problems on uDebug!