POJ3682;King Arthur's Birthday Celebration(期望)

传送门

题意

进行翻硬币实验,若k次向上则结束,进行第n次实验需花费2*n-1的费用,询问期望结束次数及期望结束费用

分析

我们令f[i]为结束概率

\[f[i]=C_{i-1}^{k-1}*p^k*(1-p)^{i-k} \]

\[\sum f[i]=1(关键) \]

\(ans1=\sum f[i]\)
\(=\sum i*C_{i-1}^{k-1}*p^k*(1-p)^{i-k}\)
\(=p^k*k*\sum C_i^k*(1-p)^{i-k}\)
\(=k/p\)
\(ans2=\sum i*i*f[i]\)
\(=k*p^k*\sum i*C_i^k*(1-p)^{i-k}\)
\(=k*p^k*\sum C_{i+1}^{k+1}*(1-p)^{i-k}-ans1\)
\(=\frac {k*(k+1)}{p^2}-ans1\)

trick

代码

#include<cstdio>
#include<cstring>

double k,p;
const double eps=1e-10;
int main()
{
    while(scanf("%lf",&k)!=EOF)
    {
        if(k<eps) break;
        scanf("%lf",&p);
        printf("%.3f %.3f\n",k/p,(k+1)*k/(p*p)-k/p);
    }
}
posted @ 2017-04-13 20:07  遗风忘语  阅读(250)  评论(0编辑  收藏  举报