ZOJ Monthly, October 2011 Prolem C

  被这套题暴虐。。。高中学的东西基本还给老师了。想了半天不知道什么是数学期望,我晕啊!!今天问师兄,答曰:数学期望就是概率的倒数。再回头想想高中残留的那点模糊的记忆,真想一头撞死!

思路:

  共n个生物,从中取出两个来,共有的情况数是,设当前有i个吸血鬼,则有n-i个人类。所以吸血鬼和人类相遇的情况数为* ,所以本次有人类变成吸血鬼的概率为

 P = **p / ,所以,本次的数学期望为1/P;

Code:

#include <iostream>
#include <cstdio>

using namespace std;

int main() {
//freopen("data.in", "r", stdin);

int T, i;
double p, ans, c, n;
scanf("%d", &T);
while(T--) {
scanf("%lf%lf", &n, &p);
c = n*(n-1)/2;
for(ans = 0, i = 1; i < n; i++) {
ans += c/((n-i)*i*p);
}
printf("%.3lf\n", ans);
}
return 0;
}



原文地址:https://www.cnblogs.com/vongang/p/2230717.html