(POJ) 3682
来源:互联网 发布:大卫罗兵逊生涯数据 编辑:程序博客网 时间:2024/06/05 10:27
King Arthur's Birthday Celebration
Description
King Arthur is an narcissist who intends to spare no coins to celebrate his coming K-th birthday. The luxurious celebration will start on his birthday and King Arthur decides to let fate tell when to stop it. Every day he will toss a coin which has probability p that it comes up heads and 1-p up tails. The celebration will be on going until the coin has come up heads for K times. Moreover, the king also decides to spend 1 thousand coins on the first day's celebration, 3 thousand coins on the second day's, 5 thousand coins on the third day's ... The cost of next day will always be 2 thousand coins more than the previous one's. Can you tell the minister how many days the celebration is expected to last and how many coins the celebration is expected to cost?
Input
The input consists of several test cases.
For every case, there is a line with an integer K ( 0 < K ≤ 1000 ) and a real number p (0.1 ≤ p ≤ 1).
Input ends with a single zero.
Output
For each case, print two number -- the expected number of days and the expected number of coins (in thousand), with the fraction rounded to 3 decimal places.
Sample Input
1 11 0.50
Sample Output
1.000 1.0002.000 6.000
Source
#include <cstdio>using namespace std;int main(){ double n,p; while(scanf("%d",&n)&&n) { scanf("%lf",&p); printf("%.3lf %.3lf\n",n/p,((n*n+n)/p*-n)/p); } return 0;}
设P(t)为举办t天生日后结束的概率,则有:
P(t) = C(t - 1, k - 1) * (1 - P)^(t-k)*P^k;
又 sigma(t = 1,+∞) P(t) = 1
sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^(t-k)*P^k = 1
(p/(1 - p))^k * sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t = 1
∴ sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t = ((1 - p)/p)^k
得出:
E = sigma(t = 1,+∞) P * t^2 (说明:sigma(t = 1,n) 2 * t - 1 = n^2)
sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^(t-k) * P^k * t^2
(p/(1 - p))^k * sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t * t^2
(p/(1 - p))^k * sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t * t^2
(p/(1 - p))^k * sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t * t^2
(p/(1 - p))^k * k * sigma(t = 1,+∞) C(t, k) * (1 - P)^t * t
在 sigma(t = 1,+∞) C(t, k) * (1 - P)^t * t 中,有:
sigma(t = 1,+∞) C(t, k) * (1 - P)^t * (t + 1) - sigma(t = 1,+∞) C(t, k) * (1 - P)^t
sigma(t = 1,+∞) C(t + 1, k) * (1 - P)^t - (1 /(1 - p)) * sigma(t = 1,+∞) C(t, k) * (1 - P)^(t + 1)
(k + 1) * sigma(t = 1,+∞) C(t + 1, k + 1) * (1 - P)^t - (1 /(1 - p)) * sigma(t = 1,+∞) C(t, k) * (1 - P)^(t + 1)
((k + 1)/(1 - p)^2) * sigma(t = 1,+∞) C(t + 1, k + 1) * (1 - P)^(t + 2) - (1 /(1 - p)) * sigma(t = 1,+∞) C(t, k) * (1 - P)^(t + 1)
代入化得:
((k + 1)/(1 - p)^2) * ((1 - p)/p)^(k + 2) - (1 /(1 - p)) * ((1 - p)/p)^(k + 1)
(k + 1) * ((1 - p)^k/p^(k + 2)) - ((1 - p)^k/p^(k + 1))
∴(p/(1 - p))^k * k * ((k + 1) * ((1 - p)^k/p^(k + 2)) - ((1 - p)^k/p^(k + 1)))
((k * (k + 1))/p^2) - k/p
(k^2 + k)/p^2 - k * p/p^2
(k^2 + k - k * p)/p^2
∴ E = (k^2 + k - k * p)/p^2
然后答案就是(k * (k + 1 - p) / (p * p))了。
- POJ 3682 (dp)
- (POJ) 3682
- poj 3682(期望dp)
- poj 1061 + poj 2115 + poj 2142 (exgcd)
- 小比赛(POJ 2992,UVALive 4108,POJ 2263,POJ 3617,HDU 5305,POJ 1988,POJ 1679,POJ 3481)
- 树状数组(poj 1195,poj 3321)
- poj 1129 (类似poj 1419)
- poj poj 3126 Prime Path(BFS)
- poj 3074/poj 3076(精确覆盖)
- poj 3264 & poj 3468(线段树)
- POJ 大数篇(POJ+百炼)
- 扩展欧几里得(poj 2115 poj 1061)
- (POJ 1003)Hangover
- POJ数学(ZZ)
- poj 3041(匈牙利)
- poj 1160(dp)
- poj 3273 (二分)
- poj 1681(高斯消元。。。)
- Java 判断文件夹、文件是否存在、否则创建文件夹
- 元素的水平垂直居中
- Keepalived+Nginx实现高可用(HA)
- 尝试解析加入域中域控制器的DNS名称失败,请验证已将此客户端已配置为连接到解析目标域中DNS名称的DNS服务器
- 宏定义
- (POJ) 3682
- tyedef的用法
- linux之修改用户密码
- Android四大组件的工作过程
- 基于Android的以太网,网线连接状态判断
- windows将nginx安装为系统服务
- n个数 找到最小的k个数 几种解法 和java实现
- jQuery选择器之元素选择器
- linux安装Yum