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

OJ-ID:
poj-3682

author:
Caution_X

date of submission:
20191031

tags:
math

description modelling:
有一个人每天抛一次硬币,直到抛出了K次正面向上才会停止,第i天的金钱花费是2*i-1,现在输入
K,问花费金钱的数学期望

major steps to solve it:
设E[i],F[i],E[i]表示抛出i次正面向上时的期望天数,F[i]表示第i天的花费金钱数学期望
(1)E[i]=1/p+W[i-1]
(2)F[i] = p*(F[i]-1 + 2 * E[i] -1)/*第i天正好得到正面向上*/ + (1-p)*(F[i] + 2 * (E[i]+1) -1) /*第i天没有得到正面向上*/

AC code:

#include <stdio.h>

double E[];
double F[]; int main()
{
int i,j,n;
double q,p;
while()
{
scanf("%d",&n);
if (n==) break;
scanf("%lf",&p);
E[]=;
F[]=;
for (i=;i<=n;i++)
{
E[i]=/p+E[i-];
F[i]=F[i-]+*E[i-]-*E[i]+(+*E[i])/p;
}
printf("%.3f %.3f\n",E[n],F[n]);
}
return ;
}

poj-3682 King Arthur's Birthday Celebration的更多相关文章

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

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

  2. POJ3682 King Arthur's Birthday Celebration

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

  3. 【概率论】【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)^( ...

  4. King Arthur's Birthday Celebration

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

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

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

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

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

  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. Cocos2d-x的坐标系统

    推荐转至此处阅读<Cocos2d-x的坐标系统> Cocos2d-x的坐标系统 一.坐标系 二.Cocos2d-x的坐标系统 1.类别 2.定义 三.屏幕坐标系 & OpenGL坐 ...

  2. Python+Unittest+Requests+PyMysql+HTMLReport 接口自动化框架

    整体框架使用的是:Python+Unittest+Requests+PyMysql+HTMLReport  多线程并发模式 主要依赖模块 Unittest.Requests.PyMysql.HTMLR ...

  3. SpringCloud学习笔记(十一、SpringCloud总结)

    SpringCloud Config: 1.动态刷新配置:通过job调用Set<String> keys = contextRefresher.refresh()这段代码即可. 2.如何实 ...

  4. IT兄弟连 HTML5教程 HTML5表单 H5表单提交综合实例

    这里我们创建一个填写个人基本信息的表单,使用了表单元素有<input>输入框.<datalist>选项列表.<textarea>文本框,通用的表单输入类型有text ...

  5. 深入理解 Java 注解

    深入理解 Java 注解 本文内容基于 JDK8.注解是 JDK5 引入的,后续 JDK 版本扩展了一些内容,本文中没有明确指明版本的注解都是 JDK5 就已经支持的注解.

  6. Redis在Window下的安装部署

    一.下载 由于redis官方不支持windows,所以需要在github上下载window的版本:下载地址.redis约定版次版本号(即第一个小数点后的数字)为偶数的版本是稳定版本(如2.8,3.0) ...

  7. SSH框架之Hibernate第四篇

    Hibernate中有两套实现数据库数据操作的方式 : hibernate前3天讲解的都是 : hibernate自己的操作方式(纯XML配置文件的方式) 另一种方式是基于JPA的操作方式(通过注解的 ...

  8. jd-gui反编译报错// INTERNAL ERROR //

    最近在反编译class和jar包的时候,发现部分class无法反编译出来,换了最新版本的jd-gui和多个版本都不行,只能放弃了 解决方案:GitHub上找Luyten这个工具反编译 luyten是P ...

  9. 利用Dynamics 365 Customer Engagement的标准导入功能导入附件。

    我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...

  10. 微服务与Spring Cloud基本概念、Spring Cloud版本命名方式与版本选择

    微服务是什么?Spring Cloud是什么?Spring Cloud版本命名方式?Spring Cloud版本选择? 一.微服务是什么 微服务是一种架构风格,是一种将单体应用开发为一组小型服务的方法 ...