现在的位置: 首页 > 综合 > 正文

Hdu 3910 Liang Guo Sha

2013年07月06日 ⁄ 综合 ⁄ 共 430字 ⁄ 字号 评论关闭

数学期望

题意:使Alice和Bob两个人拿到杀的概率互相不受影响。

分析:假设Alice拿到杀的概率是x,Bob拿到杀的概率是y,则Alice的期望是

E(x) = x*y*A + (1-x)*(1-y)*B - (1-x)*y*C - x*(1-y)*C

        = (1-x)*B - x*C + [x*A - (1-x)*B - (1-x)*C + x*C]*y

令y的系数为0,解得x = (B+C)/(A+B+2*C) , 所以E(x) = (1-x)*B - x*C

AC代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>

int main() {
	int a, b, c;
	while(scanf("%d%d%d", &a, &b, &c)!=EOF) {
		double x = (double)(b + c) / (a + b + 2 * c);
		printf("%.6lf\n", (1 - x) * b - c * x);
	}	
	return 0;
}

抱歉!评论已关闭.