10056 - What is the Probability ?
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=997
Probability has always been an integrated part of computer algorithms. Where the deterministic algorithms have failed to solve a problem in short time, probabilistic algorithms have come to the rescue. In this problem we are not dealing with any probabilistic
algorithm. We will just try to determine the winning probability of a certain player.
A game is played by throwing a dice like thing (it should not be assumed that it has six sides like an ordinary dice). If a certain event occurs when a player throws the dice (such as getting a 3, getting green side on top or whatever) he is declared the
winner. There can be N such player. So the first player will throw the dice, then the second and at last the N th player and again the first player and so on. When a player gets the desired event he or she is declared winner and playing stops. You will have
to determine the winning probability of one (The I th) of these players.
Input
Input will contain an integer S (S<=1000) at first, which indicates how many sets of inputs are there. The next S lines will contain S sets of inputs. Each line contain an integer N (N<=1000) which denotes the number players, a floating point number p which
indicates the probability of the happening of a successful event in a single throw (If success means getting 3 then p is the probability of getting 3 in a single throw. For a normal dice the probability of getting 3 is 1/6), and I (I<=N) the serial of the
player whose winning probability is to be determined (Serial no varies from 1 to N). You can assume that no invalid probability (p) value will be given as input.
Output
For each set of input, output in a single line the probability of the I th player to win. The output floating point number will always have four digits after the decimal point as shown in the sample output.
Sample Input:
2
2 0.166666 1
2 0.166666 2
Sample Output:
0.5455
0.4545
注意p=0时分母会为0,要特判。
完整代码:
/*0.016s*/
#include<cstdio>
#include<cmath>
int main()
{
int t, n, i;
double p;
scanf("%d", &t);
while (t--)
{
scanf("%d%lf%d", &n, &p, &i);
printf("%.4f\n", p == 0 ? p : p * pow(1 - p, i - 1) / (1 - pow(1 - p, n)));
}
return 0;
}
分享到:
相关推荐
This book is written for high school and college students learning about probability for the first time. It will appeal to the reader who has a healthy level of enthusiasm for understanding how and ...
Turning this around, if the probability that the random object has the property is greater than zero, then this proves the existence of at least one object in the collection that has the property....
概率之上的世界-The World Is Built On Probability
大學生必備機率聖經 擁有它就不必花3百多買書
Probability & Random Processes for Electrical and Computer Engineers
Therefore the true logic for this world is the calculus of Probabilities, which takes account of the magnitude of the probability which is, or ought to be, in a reasonable man's mind." ---James ...
随机信号处理英文教程probability and random processes This book has been written for several reasons, not all of which are academic. This material was for many years the rst half of a book in progress ...
第七版 SEVENTH EDITION,作者 JAY L. DEVORE,英文原版,统计学方向经典书籍。十分清晰
Introduction to Probability by Mark Ward & Ellen Gundlach
Probability Theory The Logic of Science Probability Theory The Logic of Science
This book will teach you the fundamental concepts that underpin probability and statistics and illustrates how they relate to machine learning via the Python language and its powerful extensions. This...
概率论与数理统计经典教材Probability And Statistics For Engineering And The Sciences (Jay L. Devore) 5th Ed. - Solution Manual 答案
This is a graduate level textbook on measure theory and probability theory. The book can be used as a text for a two semester sequence of courses in measure theory and probability theory, with an ...
This book is intended to be used as a text for either undergraduate level (junior/senior) courses in probability or introductory graduate level courses in random processes that are commonly found in ...
The book develops the necessary background in probability theory underlying diverse treatments of stochastic processes and their wide-ranging applications. With this goal in mind, the pace is lively, ...
统计学概论8版的solution Probability & Statistics for engineers and scientists 8th solution
The present book is in this tradition; it is based on the view that those cognitive skills are best acquired by solving challenging, nonstandard proba- bility problems. My own experience, both in ...
概率与统计(理工类)Probability and Statistics for Engineering and the Sciences, Jay L. Devore 8th ed。国外高校优秀教材精选,原版pdf教材
Anoka-Hennepin Schools is thrilled to release the third publication of its very own Probability and Statistics textbook. Anoka-Hennepin Probability and Statistics (Third Edition) represents the work ...