题目:
国王庆祝生日,第i天花费2i-1(千)个硬币,至于哪一天结束,给定一个正整数k,每天抛一次硬币,如果出现第k次正面朝上,就结束庆祝,正面朝上的概率为p。
问庆祝的天数和花费的金币的期望。
思路:
纯概率题,
=p^k*∑(i*c(i-1,k-1)*(1-p)^(i-k))
=k*p^k*∑(c(i,k)*(1-p)^(i-k))
=k*p^k/p^(k+1)
=k/p
cost=∑(i*i*f[i]) //第i天结束的话就花费1+3+5+...+2i-1=i*i;
=p^k*∑(i*i*c(i-1,k-1)*(1-p)^(i-k))
=k*p^k*∑(i*c(i,k)*(1-p)^(i-k))
=k*p^k*∑((i+1)*c(i,k)*(1-p)^(i-k))-p^k*∑(c(i,k)*(1-p)^(1-k))
=k*(k+1)*p^k*∑(c(i+1,k+1)*(1-p)^(i-k))-days
=k*(k+1)*p^k/(p^(k+2))-days
=k*(k+1)/p^2-days
=days*(k+1)/p-days
#include <iostream> #include <cmath> #include <stdio.h> #include <map> #include <algorithm> using namespace std; #define LL long long #define MAX 1000010 int main() { int n,k; double p; while (scanf("%d",&k),k) { scanf("%lf",&p); double ans=k/p; printf("%.3lf %.3lf\n",ans,ans*(k+1)/p-ans); } }