Hdu 3910 Liang Guo Sha

来源:互联网 发布:棋牌游戏推广软件 编辑:程序博客网 时间:2024/04/29 02:53

数学期望



题意:使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;}


原创粉丝点击