## 10056 - What is the Probability ?

Moderator: Board moderators

nejhum
New poster
Posts: 8
Joined: Sun Jun 09, 2002 9:36 pm

### 10056 - What is the Probability ?

hi all,

i have solved the prolem of probabiliy using the formula

ans = (1-p)^i-1 * p / ( 1 - (1-p)^n )

but in case of big value of n and i it gives me 0.0000 result

is this o.k.

why this is WA???
by

S M Shahed Nejhum

prom
New poster
Posts: 10
Joined: Thu Jul 25, 2002 11:58 pm
Location: Poland
Test for you
1
100 0 4

nejhum
New poster
Posts: 8
Joined: Sun Jun 09, 2002 9:36 pm
thank you

i am now solved the problem
by

S M Shahed Nejhum

nejhum
New poster
Posts: 8
Joined: Sun Jun 09, 2002 9:36 pm
thank you

i have now solved the problem
by

S M Shahed Nejhum

Pedrinho UFPE
New poster
Posts: 15
Joined: Tue Sep 10, 2002 1:56 am
Location: Brasil
Contact:

### why WA??

Hi people!

I'm tired having WA in this question!!
I real dont know why!
The case of p = 0.000000 is ok

My code is below:

[cpp]

#include <stdio.h>
#include <math.h>

double N, n, p;

scanf("%lf%lf%lf",&N,&p,&n);
}

void process() {
if(p == 0) {
printf("%.4lf\n",0);
return;
} printf("%.4lf\n",pow(1.0-p,n-1) * p / (1.0 - pow(1-p,N)));
}

void main() {
#ifndef ONLINE_JUDGE
freopen("10056.in","r",stdin);
freopen("10056.out","w",stdout);
#endif
int ncasos;
scanf("%d",&ncasos);
while(ncasos--) {
process();
}
}

[/cpp]

Please anyone know what is the problem?!!
Thanks Very much!!
Interested

Pedrinho UFPE
New poster
Posts: 15
Joined: Tue Sep 10, 2002 1:56 am
Location: Brasil
Contact:

### solved

I got AC.
The problem was precision error.
I have to print p + EPSILON...

Thanks all Interested

szymcio2001
New poster
Posts: 38
Joined: Mon Dec 09, 2002 1:53 pm
Location: Poznan, Poland

[cpp]
printf("%.4lf\n",pow(1.0-P,I-1.0)/(6.0*(1.0-pow(1.0-P,N))));
[/cpp]

It should be as follow:

[cpp]
printf("%.4lf\n",pow(1.0-P,I-1.0)/((1/P)*(1.0-pow(1.0-P,N))));
[/cpp]

Because we throw "a dice like thing" not a dice, so it can have more or less than 6 sides.

And a little hint: it's prettier to write while(S--) than for(;S;S--) dark man
New poster
Posts: 7
Joined: Fri Mar 26, 2004 11:07 pm
Contact:

### 10056

can any one help me with some good inputs and outputs of 10056. T dont know what may be the problem with this simple problem.
Try hard . May be you will get the right answer.

Rajib
New poster
Posts: 28
Joined: Tue Nov 04, 2003 6:45 am

### Check this

I think the problem is easy. But what may be the problem in your code is, there may have some kind of precisional error . Well, check this if it can solve your problem.

Input:
6
100 0.000001 1
100 0.000001 99
999 0.00023 591
2 0.0 1
915 0.166666 1
23 0.1111 13
Output:
0.0001
0.0001
0.0010
0.0000
0.1667
0.0290
Wish you to get AC gvs
New poster
Posts: 6
Joined: Sun Jun 19, 2005 7:39 pm

### somebody save me

I'm getting the following output for the following input:

[Input]:
6
100 0.000001 1
100 0.000001 99
999 0.00023 591
2 0.0 1
915 0.166666 1
23 0.1111 13

[Output]:
0.0099
0.0099
0.0010
0.0000
0.1667
0.0290

I am using float variables, and using the pow function in math.h.
Also, i am using the formula probability=p*((1-p)^(i-1))/(1-(1-p)^n)
maKe wHat yoU waNt...... you'll succeed

gvs
New poster
Posts: 6
Joined: Sun Jun 19, 2005 7:39 pm

### thanks i got AC

well, it seems, the following output was good enuf... it was an error in my mail client...
I finally got AC. maKe wHat yoU waNt...... you'll succeed

StatujaLeha
Learning poster
Posts: 91
Joined: Tue May 31, 2005 2:01 pm
Location: Russia

### I don't now where a mistake.

Hi!

I use the formula in first post for solving. This code print the result. Where is a mistake?

Code: Select all

``````                if((p != 0)&&(p != 1))
{
q = 1.0 - p;
printf("%.4lf\n",(pow(q,I - 1)*p)/(1.0 - pow(q,N)));
}
else
{
if(p == 0)
printf("%.4lf\n",0.0000);
else//p == 1
{
if(N == 1)
printf("%.4lf\n",1.0000);
else
printf("%.4lf\n",0.0000);
}
}
``````

ReiVaX18
New poster
Posts: 11
Joined: Mon Mar 29, 2004 11:53 am
Just got AC, but my program gives slightly different output:
0.0100
0.0100
0.0010
0.0000
0.1667
0.0290

StatujaLeha
Learning poster
Posts: 91
Joined: Tue May 31, 2005 2:01 pm
Location: Russia

### My program gives the same answer

My program gives the same answer, but I get WA. Can you explain your algorithm?

ReiVaX18
New poster
Posts: 11
Joined: Mon Mar 29, 2004 11:53 am
First, if the probability is zero, then the answer is zero also.

If not, for the player k to get success, the first k-1 should fail ( probability (1-p)^(k-1) ) and k should get success ( probability p ) or the n players have to fail ( probability (1-p)^n ) and then another time k-1 fails and a success or two times n fails and k-1 fails and a success or etc...

So if you calc the probabilities and sum them:

p*(1-p)^(k-1) + p*(1-p)^(k-1) * (1-p)^(n) + p*(1-p)^(k-1) * (1-p)^(2n) + ...

this is equal to

p*(1-p)^(k-1) * ( sum( i=0 to infinity, (1-p)^(i*n) ) )

the last sum is a geometric sum, so you aply the formula and get

p*(1-p)^(k-1) / ( 1 - (1-p)^n )

Note that if p = 0 the denominator is also 0, so this is why the case p = 0.0 is excluded.