您的位置:首页 > 其它

UVA - 10056 What is the Probability ? 概率UVA - 10056 What is the Probability ?

2015-01-07 11:54 453 查看
题目大意:有N个人玩掷色子游戏,只要抛到某一特定的面就算赢了,而抛到这个面的概率是P,求第M个人赢的概率

解题思路:第M个人赢的概率是:

在第一轮赢了:K1

在第二轮赢了:K2
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int main() {
	int test, N, M ;
	double p;
	scanf("%d",&test);
	while(test--) {
		scanf("%d %lf %d",&N,&p,&M);
		int time = 1;
		M--;
		double ans = p * pow(1-p,M);
		double pre = 0.0;
		while(ans - pre > 1e-7) {
			pre = ans;
			ans += p * pow(1-p,N * time + M);
			time++;	
		}
		printf("%.4lf\n",ans);
	}
	return 0;
}


...

那么赢的概率就是K = K1 + K2 + 。。。 + KN
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: