10509 - R U Kidding Mr. Feynman?

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

Moderator: Board moderators

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

Hello.

Post by Farid Ahmadov » Tue Jun 17, 2003 11:01 pm

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

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

Hello.

Post by Farid Ahmadov » Tue Jun 17, 2003 11:02 pm

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!

Post by Observer » Wed Jun 18, 2003 4:55 am

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

Post by htl » Wed Jul 02, 2003 6:14 pm

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

Post by Observer » Thu Jul 03, 2003 3:50 am

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

Post by htl » Thu Jul 03, 2003 9:20 am

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

Post by Observer » Thu Jul 03, 2003 10:36 am

OK. I think that that "+0.0000000001" should be put INSIDE the bracket...

That is, instead of
[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

Post by htl » Thu Jul 03, 2003 6:55 pm

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

Post by glyph » Tue Oct 21, 2003 4:59 pm

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:

Post by Larry » Tue Oct 21, 2003 7:06 pm

You don't exactly need pow in this problem.

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

Post by glyph » Wed Oct 22, 2003 1:16 am

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:

Post by Larry » Wed Oct 22, 2003 8:41 am

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

Post by glyph » Thu Oct 23, 2003 4:19 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?

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

10509 WA???HELP

Post by Rocky » Wed Jan 05, 2005 12:36 pm

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:

Post by Zuberul » Thu Jan 06, 2005 6:30 pm

Check your output for input 1.0000

Post Reply

Return to “Volume 105 (10500-10599)”