## 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.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7626964,"math_prob":0.94010556,"size":6531,"snap":"2019-51-2020-05","text_gpt3_token_len":2315,"char_repetition_ratio":0.113222,"word_repetition_ratio":0.7057292,"special_character_ratio":0.42091563,"punctuation_ratio":0.20329994,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9612652,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-25T04:32:57Z\",\"WARC-Record-ID\":\"<urn:uuid:40817afa-f8e7-46df-ace0-8066dee1e5ec>\",\"Content-Length\":\"73646\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1c03bad8-5015-4338-ad80-d655f42648c5>\",\"WARC-Concurrent-To\":\"<urn:uuid:cd6941f9-6bd2-4423-a259-1149a0d59bd8>\",\"WARC-IP-Address\":\"51.255.0.192\",\"WARC-Target-URI\":\"https://onlinejudge.org/board/viewtopic.php?f=9&t=1324&p=5835\",\"WARC-Payload-Digest\":\"sha1:QUJ5X2EYJ5R3HTMHFUGN7VHHNDYQIGKH\",\"WARC-Block-Digest\":\"sha1:UM6HNJ5R5Z26LBCGVUXR3K2JS5UQGWOM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579251669967.70_warc_CC-MAIN-20200125041318-20200125070318-00286.warc.gz\"}"}