## 474 - Heads / Tails Probability

Moderator: Board moderators

Sanny
Learning poster
Posts: 78
Joined: Sat Feb 14, 2004 3:59 pm
Location: BUET
Contact:
Hi,
There can be some problem in ur printf().
printf("2^-%ld = %1.3fe-%d\n",n,a[n].x,a[n].y);
The actual data types for a[n].x and a[n].y were long double and long int respectively. But u used %f and %d in the printf().

Heartattack!
New poster
Posts: 45
Joined: Fri Jan 16, 2004 7:02 pm
Location: CSE::BUET
Contact:
I've tried it with %Lf,, %lf, using strings, %f..... I think the problem is with rounding. I tried printf("%1.3Lf",...) which got WA. I added 0.00001 to the float. That too got WA. I wrote a function to round to 3 decimal digits which rounds like we do(1.00044445==1.001), and you guessed it, that got WA. Could you send me some sample output? What'll the following produce?

Code: Select all

``````11
12
13
23
24
25
7
6
47
48
49
1000000
``````
Better yet, if you got AC, could you send the code by mail? I'll only check the answers to see the required output format. I'm not one for stealing code .Thanks in advance.
We will, We will BREAK LOOP!!!!

Sanny
Learning poster
Posts: 78
Joined: Sat Feb 14, 2004 3:59 pm
Location: BUET
Contact:
My AC program gives the following output ->

Code: Select all

``````2^-11 = 4.883e-4
2^-12 = 2.441e-4
2^-13 = 1.221e-4
2^-23 = 1.192e-7
2^-24 = 5.960e-8
2^-25 = 2.980e-8
2^-7 = 7.813e-3
2^-6 = 1.563e-2
2^-47 = 7.105e-15
2^-48 = 3.553e-15
2^-49 = 1.776e-15
2^-1000000 = 1.010e-301030
``````
Hope it helps.

Heartattack!
New poster
Posts: 45
Joined: Fri Jan 16, 2004 7:02 pm
Location: CSE::BUET
Contact:
Thanks.
I changed all the ints to longs, all %ds to %lds and the %1.3lf to %1.3LF. For some reason that got AC!!!!

Proper rounding caused WA.
We will, We will BREAK LOOP!!!!

sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

### p474 get WA need sample input

i have solved problem 545 , but get WA when i submit p474
..

my algorithm is simple....

Code: Select all

``````cin>>n;
cout<<"2^"<<n<<" = ";
tmp=log10((double)2)*(n);
b=floor(tmp);
a=pow((double)10,tmp-b);
cout<<a<<'e'<<b<<endl;``````
my code here ,thanks to help me test it with your AC prog thanks

Code: Select all

``````//474 Heads / Tails Probability
///////////////////////////////
//same as 545
///////////////////////////////
#include <iostream>
#include <cmath>
using namespace std;

int main(int argc,char *argv[])
{

long n;
double a,tmp;
long b;

cout.setf(ios::fixed,ios::floatfield);
cout.precision(3);
while(cin>>n)
{

n=-n;
cout<<"2^"<<n<<" = ";
tmp=log10((double)2)*(n);
b=floor(tmp);
a=pow((double)10,tmp-b);
cout<<a<<'e'<<b<<endl;
}
}
``````

Antonio Ocampo
Experienced poster
Posts: 131
Joined: Sat Jul 17, 2004 4:09 am
Location: Lima, Per
Hi sunnycare

Have you noticed this 1<=n<=1000000 ?
So "n" doesn`t fit in an int. It should be a long long.

Hope it helps

sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai
although i have changed it to long long , OJ still give me a WA...

by the way,why to use long long ??

i think long is enough..
need help

Antonio Ocampo
Experienced poster
Posts: 131
Joined: Sat Jul 17, 2004 4:09 am
Location: Lima, Per
Hi sunnycare

You're right! int is enough

But the set of possible inputs is quite limited. You can generate them all, send me the input file and I will send you my output for it

Keep posting

sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

### need 474 sample input and output

who can send me your sample in/out sample

my mail is

thanks...

Code: Select all

``````athena_kula@msn.com
``````

thurbo
New poster
Posts: 9
Joined: Wed Apr 05, 2006 2:00 pm
Location: Stockholm, Sweden
Hi,

I also got a WA first, read this post changed my solution and got accepted.
Now the funny part is that I checked all possibilities and got the same result, except for n = 6.
My solution gave first 2^-6 = 1.563e-2 and got a WA.
Now it returns 2^-6 = 1.562e-2 and it gets accepted. In my opinion this is a wrong answer (1.5625 should round up to 1.563).
Even funnier is that my original solution gets accepted for 545 while the alternative solution gets WA...
Greetings,

Jeroen

wktang
New poster
Posts: 8
Joined: Mon Jul 03, 2006 11:27 pm
Now the funny part is that I checked all possibilities and got the same result, except for n = 6.
My solution gave first 2^-6 = 1.563e-2 and got a WA.
Now it returns 2^-6 = 1.562e-2 and it gets accepted. In my opinion this is a wrong answer (1.5625 should round up to 1.563).
This is crazy! I've got 10 WA's before I read your post.. and I added the exception case for (n = 6, which i strongly believe the correct answer to be 1.563e-2) and got AC!!! Thanks to your post again...

So isn't anyone going to correct the error? This is really frustrating... solving problems like this!

LithiumDex
New poster
Posts: 44
Joined: Tue Jun 06, 2006 6:44 pm
Contact:
I did the exact same thing, and then got AC -- If not directly a bug in the judges output, it must have been a bug or "nuance" in the library used with the code to produce that output.

Manu_bk
New poster
Posts: 2
Joined: Fri May 25, 2007 5:16 pm

### 474, Need help WA

#include <iostream>
#include <cmath>
using namespace std;

int main() {
cout.setf(ios::fixed);
cout.precision(3);
long n;
double a,tmp;
long b;
while(cin>>n) {
n=-n;
cout<<"2^"<<n<<" = ";
tmp=log10((double)2)*(n);
b=long(floor(tmp));
a=pow((double)10,tmp-b);
cout<<a<<'e'<<b<<endl;
}
}

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm
Read the forum description: don't open a thread for a problem if one exists.
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.

shopno
New poster
Posts: 1
Joined: Mon Mar 28, 2011 3:32 pm

### Re: 474 problem

You should look at the input of the 6.
The judge data does not consider the round about.
2^-6 = 1.562e-2 (The judge)
2^-6 = 1.563e-2 (Mathematical result)

Be careful. This is nothing but wasting time solving this problem/