10056  What is the Probability ?
Moderator: Board moderators
10056  What is the Probability ?
hi all,
i have solved the prolem of probabiliy using the formula
ans = (1p)^i1 * p / ( 1  (1p)^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???
i have solved the prolem of probabiliy using the formula
ans = (1p)^i1 * p / ( 1  (1p)^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
S M Shahed Nejhum

 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;
void readdata() {
scanf("%lf%lf%lf",&N,&p,&n);
}
void process() {
if(p == 0) {
printf("%.4lf\n",0);
return;
} printf("%.4lf\n",pow(1.0p,n1) * p / (1.0  pow(1p,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!!
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.0p,n1) * p / (1.0  pow(1p,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

 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
The problem was precision error.
I have to print p + EPSILON...
Thanks all
Interested

 New poster
 Posts: 38
 Joined: Mon Dec 09, 2002 1:53 pm
 Location: Poznan, Poland
Your mistake is here:
[cpp]
printf("%.4lf\n",pow(1.0P,I1.0)/(6.0*(1.0pow(1.0P,N))));
[/cpp]
It should be as follow:
[cpp]
printf("%.4lf\n",pow(1.0P,I1.0)/((1/P)*(1.0pow(1.0P,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)
[cpp]
printf("%.4lf\n",pow(1.0P,I1.0)/(6.0*(1.0pow(1.0P,N))));
[/cpp]
It should be as follow:
[cpp]
printf("%.4lf\n",pow(1.0P,I1.0)/((1/P)*(1.0pow(1.0P,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
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.
Thanks in advance.
Try hard . May be you will get the right answer.
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:
Input:
Output: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
Wish you to get AC0.0001
0.0001
0.0010
0.0000
0.1667
0.0290
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
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*((1p)^(i1))/(1(1p)^n)
[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*((1p)^(i1))/(1(1p)^n)
maKe wHat yoU waNt...... you'll succeed
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.
I finally got AC.
maKe wHat yoU waNt...... you'll succeed

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

 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?
First, if the probability is zero, then the answer is zero also.
If not, for the player k to get success, the first k1 should fail ( probability (1p)^(k1) ) and k should get success ( probability p ) or the n players have to fail ( probability (1p)^n ) and then another time k1 fails and a success or two times n fails and k1 fails and a success or etc...
So if you calc the probabilities and sum them:
p*(1p)^(k1) + p*(1p)^(k1) * (1p)^(n) + p*(1p)^(k1) * (1p)^(2n) + ...
this is equal to
p*(1p)^(k1) * ( sum( i=0 to infinity, (1p)^(i*n) ) )
the last sum is a geometric sum, so you aply the formula and get
p*(1p)^(k1) / ( 1  (1p)^n )
Note that if p = 0 the denominator is also 0, so this is why the case p = 0.0 is excluded.
If not, for the player k to get success, the first k1 should fail ( probability (1p)^(k1) ) and k should get success ( probability p ) or the n players have to fail ( probability (1p)^n ) and then another time k1 fails and a success or two times n fails and k1 fails and a success or etc...
So if you calc the probabilities and sum them:
p*(1p)^(k1) + p*(1p)^(k1) * (1p)^(n) + p*(1p)^(k1) * (1p)^(2n) + ...
this is equal to
p*(1p)^(k1) * ( sum( i=0 to infinity, (1p)^(i*n) ) )
the last sum is a geometric sum, so you aply the formula and get
p*(1p)^(k1) / ( 1  (1p)^n )
Note that if p = 0 the denominator is also 0, so this is why the case p = 0.0 is excluded.