LightOJ-1248-Dice (III) (数学期望)

来源:互联网 发布:sister组合shake it 编辑:程序博客网 时间:2024/05/15 23:46

题目链接:LightOJ-1248-Dice (III)

当已经获得 k 面时,想要获得 k+1 面,每掷一次能获得 k+1 的概率是 nkn ,期望是 nnk

故期望为 ans=nni=11i

#include<bits/stdc++.h>using namespace std;int main(){    int T,kase=1;    scanf("%d",&T);    while(T--)    {        int n;        scanf("%d",&n);        double ans=0;        for(int i=1;i<=n;i++)            ans+=1.0/i;        printf("Case %d: %.15f\n",kase++,ans*n);    }    return 0;}
0 0
原创粉丝点击