当前位置:网站首页>Poj3682 king arthur's birthday celebration (probability)
Poj3682 king arthur's birthday celebration (probability)
2022-06-26 09:58:00 【yuyanggo】
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2886 | Accepted: 905 |
Description
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
Source
analysis :ans1=k/p
ans2=k*(k+1)/p/p-k/p
Code :
#include<cstdio>
using namespace std;
int main()
{
//freopen("1.in","r",stdin);
int k; double p;
while(scanf("%d%lf",&k,&p)&&k!=0)
{
printf("%.3f ",k/p);
printf("%.3f\n",k*(k+1)/p/p-k/p);
}
return 0;
}边栏推荐
- 逻辑英语结构【重点】
- thinkphp6.0的第三方扩展包,支持上传阿里云,七牛云
- echo $?
- Specific implementation comparison between different programming languages
- LeetCode 498. Diagonal traversal
- Common SQL add / delete / modify query statements
- 爬虫相关文章收藏:pyppeteer 、Burpsuite
- 我在中山,到哪里开户比较好?在线开户安全么?
- 动态库连接 - 符号冲突 - 全局符号介入
- Wechat official account reported error 10003
猜你喜欢

Redis 新手入门

Redis novice introduction

调用api接口生成不同颜色的微信小程序二维码

Specific implementation comparison between different programming languages

Configuration internationale

Deep learning (tentsorflow2. version) three good student performance problems (1)

DAY 3 数组,前置后置,字符空间,关键词和地址指针

Basic grammar of C language -- pointer (character, one-dimensional array) learning

c语言语法基础之——指针( 多维数组、函数、总结 ) 学习

c语言语法基础之——指针(字符、一维数组) 学习
随机推荐
Single sign on logic
我在中山,到哪里开户比较好?在线开户安全么?
LeetCode 接雨水系列 42.(一维) 407.(二维)
cento7.7安装ELK简单记录
What you need to know to test -- URL, weak network, interface, automation
MySQL learning summary
Crawler related articles collection: pyppeter, burpsuite
Learning and understanding of thread pool (with code examples)
LeetCode 基本计算器 224. 227. follow up 394
2021-11-12 vrep vision sensor configuration
#云原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service
Custom interceptor
Opencv depthframe - > pointcloud causes segmentation fault!
爬虫相关文章收藏:pyppeteer 、Burpsuite
Control setting layout in linear layout_ Gravity doesn't work?
Automated testing -- Introduction and use of pytest itself and third-party modules
Redis novice introduction
WGCLOUD的web ssh服务端口是多少
LeetCode 958. Completeness checking of binary tree
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.npm ER