UVA 10056 - What is the Probability ?(概率)
来源:互联网 发布:淘宝店怎么铺货 编辑:程序博客网 时间:2024/04/28 09:45
Problem B
What is the Probability?
Input: standard input
Output: standard output
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:
22 0.166666 1
2 0.166666 2
Sample Output:
0.54550.4545
_____________________________________________________________________
题意:n个人,每个人赢的概率是p,求第m个人赢的概率。
思路:p = p1 + p2 + p3 + p4 +...pn p为每轮第m个人赢的概率。可以推成等比数列前n项和公式,n趋近正无穷。但是我是直接设了个最小值0.000001就可以了。
代码:
#include <stdio.h>#include <math.h>int T, n, m, i, j;double p;int main() {scanf("%d", &T);while (T --) {scanf("%d%lf%d", &n, &p, &m);double ans = 0;double save = 1.0;double q = pow((1 - p), n);save *= pow((1 - p), m - 1);save *= p;while (save > 0.000001) {ans += save;save *= q;}printf("%.4lf\n", ans);}return 0;}
- What is the Probability - UVa 10056 概率
- uva 10056 - What is the Probability ?(概率)
- UVA 10056 - What is the Probability ?(概率)
- UVA - 10056 What is the Probability ?(概率)
- UVA - 10056 What is the Probability ? 概率UVA - 10056 What is the Probability ?
- UVa 10056 What is the Probability ? (概率&有一个陷阱)
- uva 10056 What is the Probability ?(简单概率)
- uva 10056 What is the Probability ? 概率是多少
- UVA10056 - What is the Probability ?(概率)
- uva 10056 - What is the Probability ?
- UVA - 10056 What is the Probability ?
- UVa:10056 What is the Probability ?
- UVa 10056 — What is the Probability?
- uva 10056 What is the Probability ?
- UVA - 10056 What is the Probability ?
- UVA 10056 What is the Probability ?
- uva10056 - What is the Probability ?(概率是多少)
- 10056 - What is the Probability ?
- 面向接口编程
- sdut 2189 基友记(用一个count数组记录出现的个数)
- 锦州平凉遵义湘潭南京栖霞1383829293881
- 衢州福安宁德高要1383829445531
- 衡水宁德遵化新余1383829448265
- UVA 10056 - What is the Probability ?(概率)
- 滕州晋州荆州河源大庆吉安1383829328951
- 汉川遵义丹阳常宁1383829468984
- NoSql比较知名的产品
- HTML5分享:Canvas多点触控规模与KineticJS形状
- 屏的调试
- 德阳贵港登封常宁咸阳通州1383829359335
- 谁在说谎 c,java实现
- 曲靖珠海合肥四平江油江山1383829367457