LightOJ 1218 概率水题(几何分布)

**题意:**给你一个n面骰子,问你投出所有面需要的次数的期望值是多少。 **题解:**放在过去估计秒解,结果现在自己想好久,还查了下,有人用极限证明...实际上仔细想想这种情况投出与前面不一样的概率p的倒数就是次数的期望值阿!好菜 后面再查了下是几何分布,离散型的...
/** @Date    : 2016-10-26-19.01
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link :
* @Version : $
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#define LL long long
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+2000;
int main()
{
int T;
int cnt = 0;
cin >> T;
while(T--)
{
double n;
scanf("%lf", &n);
double ans = 1;
//n面骰子 投出和前面k次不一样的概率为p = n-k/n,
//为了使这种情况发生 期望值为1/p
for(double i = 1; i < n; i++)
ans += n/(n-i);
printf("Case %d: %.10lf\n", ++cnt, ans);
}
return 0;
}
posted @ 2016-10-28 16:35  Lweleth  阅读(258)  评论(0编辑  收藏  举报