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 1
1 0.5
0

Sample Output

1.000 1.000
2.000 6.000

数学问题 数学期望 递推

水道期望题,防止自己彻底忘掉期望是个啥……

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mxn=;
double f[mxn],g[mxn];
double p;
int n;
int main(){
int i,j;
while(scanf("%d",&n)!=EOF && n){
scanf("%lf",&p);
for(i=;i<=n;i++){
f[i]=1.0/p+f[i-];
g[i]=(g[i-]+*(f[i-]+)-)+(-p)*(*(f[i]+)-)/p;
}
printf("%.3f %.3f\n",f[n],g[n]);
}
return ;
}

POJ3682 King Arthur's Birthday Celebration的更多相关文章

  1. poj-3682 King Arthur's Birthday Celebration

    C - King Arthur's Birthday Celebration POJ - 3682 King Arthur is an narcissist who intends to spare ...

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

    传送门 题意 进行翻硬币实验,若k次向上则结束,进行第n次实验需花费2*n-1的费用,询问期望结束次数及期望结束费用 分析 我们令f[i]为结束概率 \[f[i]=C_{i-1}^{k-1}*p^k* ...

  3. [POJ3682]King Arthur's Birthday Celebration[期望DP]

    也许更好的阅读体验 \(\mathcal{Description}\) 每天抛一个硬币,硬币正面朝上的几率是p,直到抛出k次正面为止结束,第\(i\)天抛硬币的花费为\(2i-1\),求出抛硬币的天数 ...

  4. 【概率论】【POJ 3682】【King Arthur's Birthday Celebration】

    题意:进行翻硬币实验,若k次向上则结束,进行第n次实验需花费2*n-1的费用,询问期望结束次数及期望结束费用 设F[i]为第i次结束时的概率 F[i]=  c(i-1,k-1)*p^k*(1-p)^( ...

  5. King Arthur's Birthday Celebration

    每天抛一个硬币,硬币正面朝上的几率是p,直到抛出k次正面为止结束,第一天抛硬币需花费1,第二天花费3,然后是5,7,9……以此类推,让我们求出抛硬币的天数的期望和花费的期望. 天数期望: A.投出了k ...

  6. poj 3682 King Arthur's Birthday Celebration (期望dp)

    传送门 解题思路 第一问比较简单,设$f[i]​$表示扔了$i​$次正面向上的硬币的期望,那么有转移方程 : $f[i]=f[i]*(1-p)+f[i-1]*p+1​$,意思就是$i​$次正面向上可以 ...

  7. POJ3682King Arthur's Birthday Celebration(数学期望||概率DP)

    King Arthur is an narcissist who intends to spare no coins to celebrate his coming K-th birthday. Th ...

  8. hdu4337 King Arthur's Knights

    King Arthur's Knights Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...

  9. hdu 4337 King Arthur's Knights (Hamilton)

    King Arthur's KnightsTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

随机推荐

  1. 程序在Linux下前后台切换

    程序在Linux下前后台切换 一.为什么要使程序在后台执行 背景:SecureCRT远程连接到linux主机,使程序在后台运行有以下好处: (1)本机关机不影响linux主机运行 (2)不影响计算效率 ...

  2. android activity状态保存

    一.被其他任务打断(来电话),再次打开希望保留数据 private String SAVE_INSTANCE_TAG = "ATWAL"; @Override protected ...

  3. 时屏蔽ios和android下点击元素时出现的阴影

    -webkit-tap-highlight-color -webkit-tap-highlight-color:rgba(255,255,255,0)

  4. fiddler显示出服务器IP方法

    fiddler的配置中是看不到服务器的IP的 1.打开进入fiddler界面,按快捷键ctrl+r 或者按照图中点击,进入customrules.js文件里. 2.在customrules.js文件里 ...

  5. 第七篇数字&字符串之练习题

    1.执行Python脚本的两种方式2.简述位.字节的关系3.简述ascii.unicode.utf-­‐8.gbk的关系4.请写出“李杰”分别用utf-­‐8和gbk编码所占的位数5.Pyhton单行 ...

  6. 利用devcon工具编写bat脚本一键控制系统设备,如开启关闭网卡

    系统WIN7 x64位 下载devcon命令行工具 Download the "Windows Driver Kit (WDK) 7.1.0 from Microsoft: http://w ...

  7. NO2——最短路径

    [Dijkstra算法] 复杂度O(n2) 权值必须非负 /* 求出点beg到所有点的最短路径 */ // 邻接矩阵形式 // n:图的顶点数 // cost[][]:邻接矩阵 // pre[i]记录 ...

  8. 【翻译】介绍 ASP.NET Core 中的 Razor Pages

    介绍 ASP.NET Core 中的 Razor Pages 原文地址:Introduction to Razor Pages in ASP.NET Core         译文地址:介绍 asp. ...

  9. 个人作业4——alpha阶段个人总结1

    一.个人总结 在alpha 结束之后, 每位同学写一篇个人博客, 总结自己的alpha 过程: 总体来说,这次的alpha并不是很顺利,编程是基础,如果对语言不是很熟悉的话,一个团队是很难开发出什么东 ...

  10. EF to linq 左连接

    如果连接的数据不存在用 null 表示,则可以左连接查询,但是如果数据类型为 int 则会出错. var ng = (from g in _db.NET_NEWS_GROUP join z in _d ...