10056 - What is the Probability ?

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

Moderator: Board moderators

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

10056 - What is the Probability ?

Post by nejhum » Fri Sep 13, 2002 8:57 pm

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

Post by prom » Fri Sep 13, 2002 10:40 pm

Test for you
1
100 0 4

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

Post by nejhum » Sat Sep 14, 2002 4:17 am

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

Post by nejhum » Sat Sep 14, 2002 4:17 am

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

Post by Pedrinho UFPE » Wed Oct 23, 2002 3:54 am

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!!
Interested

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

solved

Post by Pedrinho UFPE » Wed Oct 23, 2002 4:28 am

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

Thanks all :-)
Interested

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

Post by szymcio2001 » Mon Jun 30, 2003 2:33 pm

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

dark man
New poster
Posts: 7
Joined: Fri Mar 26, 2004 11:07 pm
Contact:

10056

Post by dark man » Fri Apr 23, 2004 6:14 pm

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.
Try hard . May be you will get the right answer.

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

Check this

Post by Rajib » Sat Jun 19, 2004 9:05 am

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 :D

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

somebody save me

Post by gvs » Tue Jun 21, 2005 8:05 pm

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)
maKe wHat yoU waNt...... you'll succeed

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

thanks i got AC

Post by gvs » Tue Jun 21, 2005 8:07 pm

well, it seems, the following output was good enuf... it was an error in my mail client...
I finally got AC.
:D
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.

Post by StatujaLeha » Sun Oct 16, 2005 11:59 am

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

Post by ReiVaX18 » Sun Oct 16, 2005 12:34 pm

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

Post by StatujaLeha » Sun Oct 16, 2005 3:36 pm

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

Post by ReiVaX18 » Sun Oct 16, 2005 6:32 pm

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.

Post Reply

Return to “Volume 100 (10000-10099)”