POJ3682 King Arthur's Birthday Celebration
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的更多相关文章
- poj-3682 King Arthur's Birthday Celebration
C - King Arthur's Birthday Celebration POJ - 3682 King Arthur is an narcissist who intends to spare ...
- POJ3682;King Arthur's Birthday Celebration(期望)
传送门 题意 进行翻硬币实验,若k次向上则结束,进行第n次实验需花费2*n-1的费用,询问期望结束次数及期望结束费用 分析 我们令f[i]为结束概率 \[f[i]=C_{i-1}^{k-1}*p^k* ...
- [POJ3682]King Arthur's Birthday Celebration[期望DP]
也许更好的阅读体验 \(\mathcal{Description}\) 每天抛一个硬币,硬币正面朝上的几率是p,直到抛出k次正面为止结束,第\(i\)天抛硬币的花费为\(2i-1\),求出抛硬币的天数 ...
- 【概率论】【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)^( ...
- King Arthur's Birthday Celebration
每天抛一个硬币,硬币正面朝上的几率是p,直到抛出k次正面为止结束,第一天抛硬币需花费1,第二天花费3,然后是5,7,9……以此类推,让我们求出抛硬币的天数的期望和花费的期望. 天数期望: A.投出了k ...
- poj 3682 King Arthur's Birthday Celebration (期望dp)
传送门 解题思路 第一问比较简单,设$f[i]$表示扔了$i$次正面向上的硬币的期望,那么有转移方程 : $f[i]=f[i]*(1-p)+f[i-1]*p+1$,意思就是$i$次正面向上可以 ...
- 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 ...
- hdu4337 King Arthur's Knights
King Arthur's Knights Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 4337 King Arthur's Knights (Hamilton)
King Arthur's KnightsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- asp.net mvc 无刷新加载
1.视图(index) <!--start--> <div data-am-widget="list_news" class="am-list-news ...
- 【jQuery】 资料
[jQuery] 资料 1. 选择器 http://www.w3school.com.cn/jquery/jquery_ref_selectors.asp 2. 事件 http://www.w3sch ...
- Python-学习-import语句导入模块
简单的学习一下调用外部的模块文件. 在Python中,模块是一种组织形式,它将彼此有关系的Pyrhon 代码组织到一个个独立的文件当中,模块可以包含可执行代码,函数,和类或者是这些东西的组合. 当我们 ...
- 再见NullPointerException。在Kotlin里null的处理(KAD 19)
作者:Antonio Leiva 时间:Apr 4, 2017 原文链接:https://antonioleiva.com/nullity-kotlin/ 关于Kotlin最重要的部分之一:无效处理, ...
- 7.0 启动app权限弹窗问题
这里提供两种解决方案! 1.安卓6.0+是可以直接利用uiautomator定位元素点击!这个不细说,定位方式很多种...这个等待时间大家自己定大概两到三秒即可! #安卓6.0+点击方式driver. ...
- #Spring实战第二章学习笔记————装配Bean
Spring实战第二章学习笔记----装配Bean 创建应用对象之间协作关系的行为通常称为装配(wiring).这也是依赖注入(DI)的本质. Spring配置的可选方案 当描述bean如何被装配时, ...
- word2vec是如何工作的?
如何有效的将文本向量化是自然语言处理(Natural Language Processing: NLP)领域非常重要的一个研究方向.传统的文本向量化可以用独热编码(one-hot encoding). ...
- MySQL初识3
随着对MySQL的熟识,今次总结一下MySQL数据库的删除.备份和还原操作 1.数据库的删除: a.删除数据库的命令:drop database dbname; b.删除数据库中的表: 单个表:dro ...
- 【Python】python函数每日一讲 - dir()
最近确实是有些忙,刚过了年,积攒了很多事情需要处理,所以每日一函数只能是每两天更新一篇,在这里和大家致歉. 今天我们来看一个非常重要的函数:dir() 中文说明:不带参数时,返回当前范围内的变量.方法 ...
- Android java.lang.NoClassDefFoundError的错误
在开发过程中,遇到一个这样的问题:java.lang.NoClassDefFoundError: android.support.v4.util.SparseArrayCompat,这个问题很奇怪,J ...