Page **1** of **2**

### 10056 - What is the Probability ?

Posted: **Fri Sep 13, 2002 8:57 pm**

by **nejhum**

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

Posted: **Fri Sep 13, 2002 10:40 pm**

by **prom**

Test for you

1

100 0 4

Posted: **Sat Sep 14, 2002 4:17 am**

by **nejhum**

thank you

i am now solved the problem

Posted: **Sat Sep 14, 2002 4:17 am**

by **nejhum**

thank you

i have now solved the problem

### why WA??

Posted: **Wed Oct 23, 2002 3:54 am**

by **Pedrinho UFPE**

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;

void readdata() {

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--) {

readdata();

process();

}

}

[/cpp]

Please anyone know what is the problem?!!

Thanks Very much!!

### solved

Posted: **Wed Oct 23, 2002 4:28 am**

by **Pedrinho UFPE**

I got AC.

The problem was precision error.

I have to print p + EPSILON...

Thanks all

Posted: **Mon Jun 30, 2003 2:33 pm**

by **szymcio2001**

Your mistake is here:

[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--)

### 10056

Posted: **Fri Apr 23, 2004 6:14 pm**

by **dark man**

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.

Thanks in advance.

### Check this

Posted: **Sat Jun 19, 2004 9:05 am**

by **Rajib**

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

### somebody save me

Posted: **Tue Jun 21, 2005 8:05 pm**

by **gvs**

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

can anybody please help me.

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)

### thanks i got AC

Posted: **Tue Jun 21, 2005 8:07 pm**

by **gvs**

well, it seems, the following output was good enuf... it was an error in my mail client...

I finally got AC.

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

Posted: **Sun Oct 16, 2005 11:59 am**

by **StatujaLeha**

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

Posted: **Sun Oct 16, 2005 12:34 pm**

by **ReiVaX18**

Just got AC, but my program gives slightly different output:

0.0100

0.0100

0.0010

0.0000

0.1667

0.0290

### My program gives the same answer

Posted: **Sun Oct 16, 2005 3:36 pm**

by **StatujaLeha**

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

Posted: **Sun Oct 16, 2005 6:32 pm**

by **ReiVaX18**

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.