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

X123
New poster
Posts: 11
Joined: Fri Oct 04, 2013 1:28 am

Re: 11428 - Cubes

Post by X123 »

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.

X123
New poster
Posts: 11
Joined: Fri Oct 04, 2013 1:28 am

Re: 11428-I am tired getting WA again& again

Post by X123 »

Sorry
Many of life’s failures are people who did not realize how close they were to success when they gave up.

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

Re: 11428 - Cubes

Post by brianfry713 »

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!

X123
New poster
Posts: 11
Joined: Fri Oct 04, 2013 1:28 am

Re: 11428 - Cubes

Post by X123 »

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]
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.

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

Re: 11428 - Cubes

Post by brianfry713 »

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!

X123
New poster
Posts: 11
Joined: Fri Oct 04, 2013 1:28 am

Re: 11428 - Cubes

Post by X123 »

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.

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

Re: 11428 - Cubes

Post by brianfry713 »

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!

unreleased
New poster
Posts: 16
Joined: Sun Nov 10, 2013 7:41 pm

11428 - Cubes why WA?????

Post by unreleased »

#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;

}

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

Re: 11428 - Cubes

Post by brianfry713 »

Next time post in the existing thread. Input 1, AC output No solution
Check input and AC output for thousands of problems on uDebug!

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11428 - Cubes

Post by lighted »

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

unreleased
New poster
Posts: 16
Joined: Sun Nov 10, 2013 7:41 pm

Re: 11428 - Cubes

Post by unreleased »

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.....

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11428 - Cubes

Post by lighted »

Input

Code: Select all

1
8
0
Acc output

Code: Select all

No solution
No solution
Your output

Code: Select all

1 0
2 0
Both x, y must be positive.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

shaficse
New poster
Posts: 5
Joined: Sun Aug 17, 2014 8:20 pm

Re: 11428 - Cubes

Post by shaficse »

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;
}

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11428 - Cubes

Post by lighted »

Use code tags. :)
Input

Code: Select all

8
721
728
999
3367
5768
5824
7992
0
Output

Code: Select all

No solution
9 2
9 1
10 1
15 2
18 4
18 2
20 2
shaficse wrote:i am getting WA but i got accurate answer using http://www.udebug.com/UVa/11428 output:
According to problem description
Each of these lines contains two positive integers x, y separated by a single space, such that N = x^3 - y^3.
Maybe Judge doesn't have input when N = x^3.

It will be good if you remove all your codes after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

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

Re: 11428 - Cubes

Post by brianfry713 »

try solving it without using floating point
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 114 (11400-11499)”