题目连接:uva 10056 - What is the Probability ?
题目大意:给出n和p以及m,表示有n个人在丢色子, 谁先丢到某个值就表示胜利,每个人丢到的胜利数值的概率都为p,问第m个人获胜概率。
解题思路:因为n个人可以轮流丢色子,所以要自己定一个下限,而且以为人数比较多,每次并不需要将m以外的人都考虑进去,可以默认为没有丢到胜利的数值。
#include <stdio.h>const double tmp = 1e-7;int main () { int cas, n, aid; double p, q; scanf("%d", &cas); while (cas--) { scanf("%d%lf%d", &n, &p, &aid); double ans = 0, c = p, q = 1; for (int i = 1; i <= n; i++) { if (i < aid) c *= (1 - p); q *= (1 - p); } while (c > tmp) { ans += c; c *= q; } printf("%.4lf\n", ans); } return 0;}
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.youkuaiyun.com/jiangjunshow