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. ubuntu设置ssh登陆

    转: 默认请况下,ubuntu是不允许远程登陆的.(因为服务没有开,可以这么理解.) 想要用ssh登陆的话,要在需要登陆的系统上启动服务.即,安装ssh的服务器端 $ sudo apt-get ins ...

  2. ibatis常用sql

    (1) 输入参数为单个值 <delete id="com.fashionfree.stat.accesslog.deleteMemberAccessLogsBefore" p ...

  3. 「日常训练」「小专题·USACO」 Ski Course Design (1-4)

    题目 以后补 分析 mmp这题把我写蠢哭了 我原来的思路是什么呢? 每轮找min/max,然后两个决策:升min/降max 像这样子dfs找最优,然后花式剪枝 但是一想不对啊,这才1-4,哪有那么复杂 ...

  4. Lambda表达式在Kotlin中怎样工作的:setOnClickListener的转换(KAD 18)

    作者:Antonio Leiva 时间:Mar 28, 2017 原文链接:https://antonioleiva.com/lambdas-kotlin-android/ 虽然,我在其它文章讲过一点 ...

  5. MySQL☞between ... and ...

    between  初值  and  终值:求出该列列值在初值和终值之间所有的数据 格式如下: select 列名/* from 表名 where 列名 between 初值 and 终值 如下图:

  6. 玩玩自动化测试之selenium篇

    现如今社会科技发展太快了,纯功能点点点已经落后别人好几条街了,所以为了让自己多点职业生涯年限,得挺起肩,傲起头.自动化测试,其本质是用代码程序测试程序,所以其实第一步应该学好编程语言,后再自己开发自动 ...

  7. ThinkPHP5项目目录规划实践

    ThinkPHP5安装后(或者下载后的压缩文件解压后)可以看到下面的目录结构: tp5├─application     应用目录 ├─extend          扩展类库目录(可定义) ├─pu ...

  8. TensorFlow 同时调用多个预训练好的模型

    在某些任务中,我们需要针对不同的情况训练多个不同的神经网络模型,这时候,在测试阶段,我们就需要调用多个预训练好的模型分别来进行预测. 调用单个预训练好的模型请点击此处 弄明白了如何调用单个模型,其实调 ...

  9. [boost-3] 函数对象

    boost库学习: 函数对象,成为‘高阶函数’,可以呗传入到其他函数或者从其他函数返回的一类函数. Boost.Bind可替换来自c++标准中的std::bind1st()和std::bind2dn( ...

  10. 轻量级权限管理系统——MVC基础

    Microsoft Web 开发平台