## 10509 - R U Kidding Mr. Feynman?

Moderator: Board moderators

Experienced poster
Posts: 131
Joined: Thu Apr 17, 2003 8:39 am
Location: Baku, Azerbaijan

### Hello.

It's me again.
I used that formula and got AC.
When you find a: a := int(exp((1/3)*ln(n))+0.0000000001);

That's all you need to do!

And you'll all get AC. I did it at C too and now I am on the 9-th place in statistics.
_____________
NO sigNature

Experienced poster
Posts: 131
Joined: Thu Apr 17, 2003 8:39 am
Location: Baku, Azerbaijan

### Hello.

It's me again.
I used that formula and got AC.
When you find a: a := int(exp((1/3)*ln(n))+0.0000000001);

That's all you need to do!

And you'll all get AC. I did it at C too and now I am on 9-th place in statistics.
_____________
NO sigNature

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

### Re: I don't like the judge!

Finally, the Judge did something.

They added a special judging program for this qq.

Now there are no more WAs!!!!
(See ranklist: http://acm.uva.es/cgi-bin/OnlineJudge?ProblemStat:10509)
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

### 10509

Can someone help me with my code?? I'm really poor at the precision prob.
[c]
#include<stdio.h>
#include<math.h>
void main(void)
{
double n,a;
while(1)
{
scanf("%lf",&n);
if(n==0)
break;
a=ceil(pow(n,1.0/3.0))+0.0000000001;
if(a*a*a>n)
a--;
printf("%.4lf\n",(n+2*a*a*a)/3/a/a);
}
}
[/c]

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
I'm afraid your code cannot even get the sample i/o correct......

That means your rounding function is incorrect:
[cpp] a=ceil(pow(n,1.0/3.0))+0.0000000001;[/cpp](Why +0.0000000001 ??)

And why do you declare a as double? After all a should always be an integer!!!

Change it and you'll get AC!
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan
I saw it in other articles that adding 0.0000000001 can improve the precision...

I modified the code and still got WA...
[c]
#include<stdio.h>
#include<math.h>
void main(void)
{
long a;
double n;
while(1)
{
scanf("%lf",&n);
if(n==0)
break;
a=pow(n,1.0/3.0);
printf("%.4lf\n",(n+2*a*a*a)/3/a/a);
}
}
[/c]

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
OK. I think that that "+0.0000000001" should be put INSIDE the bracket...

[cpp]ceil(pow(n,1.0/3.0))+0.0000000001;[/cpp]you should have [cpp]ceil(pow(n,1.0/3.0)+0.0000000001);[/cpp]or simply this will do in this qq: [cpp]ceil(pow(n,1.0/3.0));[/cpp]
You should keep this:[cpp] if(a*a*a>n)
a--; [/cpp]
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan
I got AC. And you're a great helper! Thanks!

glyph
New poster
Posts: 3
Joined: Tue Oct 21, 2003 4:55 pm

### 10509 - speed??

Hi! I've got the usual solution in C++ for 10509, using pow() and a really short program but I get 0.600 seconds. I'm wondering, how the heck can people get 0.244 seconds in C++ for this program? I have tried precomputed look-up tables for my cubes, linear search through the table, binary search, etc. Nothing comes close.

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:
You don't exactly need pow in this problem.

glyph
New poster
Posts: 3
Joined: Tue Oct 21, 2003 4:55 pm
Did you notice that I mentioned I tried look-up tables and binary searches and linear searches??? And they were slower??? Tell me, what is faster than pow()?

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:
Unless you're doing in the problem in a weird way, something like:

k * k * k should be enough..

glyph
New poster
Posts: 3
Joined: Tue Oct 21, 2003 4:55 pm
Yes, one of my attempts was to use k*k*k and a linear search though all k (faster than binary search because k is small) to find the right k, and another attempt was to use a hard-coded lookup table of cubes plus linear search to find k, and again everything is way slower than my k = int(pow(n, 1.0/3.0) + 1e-12) solution. Is there any magic way to get the correct k?

Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:

### 10509 WA???HELP

HY Everybody
There Is Another Easy PROBLEM 10509 (R U KIDDING...).
BUT I GET WRONG ANSWER,BUT I DONT KNOW WHY
PLS.. CAN ANYONE GIVE ME SOME CRITICAL INPUT/OUTPT
THAT I CAN UNDERSTAND WHY WRONG ANSWER.....PLS......

Zuberul
New poster
Posts: 28
Joined: Sun Oct 24, 2004 9:46 pm
Location: dhaka
Contact:
Check your output for input 1.0000