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. phpMyAdmin开启IP地址登录

    根本没有其他文章说的那么麻烦,又是修改配置文件,又是修改首页文件.在根目录下有个libraries文件夹,进去有个config.default.php文件,修改里面的AllowArbitrarySer ...

  2. a minimum of subsistence

    A hundred years ago it was assumed and scientifically "proved" by economists that the laws ...

  3. 用dotnet core搭建web服务器(三)ORM访问数据库

    访问传统sql数据库,大家以前都是用sql语句去查询.这些年流行orm方法 ORM是对象关系映射的简拼,就是用一个对象(class)去表示数据的一行,用对象的成员去表述数据的列 dotnet 官方很早 ...

  4. Python爬虫的概括以及实战

    第一章主要讲解爬虫相关的知识如:http.网页.爬虫法律等,让大家对爬虫有了一个比较完善的了解和一些题外的知识点.​ 今天这篇文章将是我们第二章的第一篇,我们从今天开始就正式进入实战阶段,后面将会有更 ...

  5. Thymeleaf实现页面静态化

    如果用户所有的请求,都需要Thyleaf渲染后直接返回给用户,后台就存在大量的查询操作,数据库的压力就会骤然上升,请求的时间就会延长,带来极不好用户体验,现在市面上流行的就是页面的静态化处理,下面就来 ...

  6. Java 添加Word脚注、尾注

    Word中的脚注和尾注都是对文本的补充说明.脚注一般是附在书页最左下端的注文,用以解释.说明特定内容:而尾注则是位于文档末尾,用于列出引文的出处.脚注和尾注都可以是针对某些文字或者段落来添加.本文中, ...

  7. git worktree 使用笔记

    一 worktree 的基本概念和操作 再也不用克隆多个仓库啦!git worktree 一个 git 仓库可以连接多个工作目录 - walterlv的专栏 - CSDN博客 再也不用克隆多个仓库啦! ...

  8. Python:多态、协议和鸭子类型

    多态 问起面向对象的三大特性,几乎每个人都能对答如流:封装.继承.多态.今天我们就要来说一说 Python 中的多态. 所谓多态:就是指一个类实例的相同方法在不同情形有不同表现形式.多态机制使具有不同 ...

  9. JavaScript动态加载script方式引用百度地图API,Uncaught ReferenceError: BMap is not defined

    百度地图官网文档介绍使用JSSDK时,仅提供了2种引入方式: script引入 异步加载 实际工作场景中仅某一两个页面或者只是单纯有功能需要用到百度地图,所以没有必要在 index.html 中全局引 ...

  10. redis windows版安装

    首先到 https://github.com/ServiceStack/redis-windows 下载redis 然后将下载的文件解压 然后获取里面的这个压缩包并且解压 这是2.8.2101版本的, ...