当前位置:网站首页>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;
}
边栏推荐
- Leetcode basic calculator 224 227. follow up 394
- SQL function
- LeetCode 剑指 Offer II 091.粉刷房子 - 原地修改
- 测试实践——app 测试注意点
- Common SQL add / delete / modify query statements
- Solution to network request crash in retrofit2.8.1
- install ompl. sh
- Retrofit common request methods and comments, post, get heard file upload
- The basis of C language grammar -- function definition learning
- LeetCode 958. Completeness checking of binary tree
猜你喜欢
定制拦截器
#云原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service
做测试需要知道的内容——url、弱网、接口、自动化、
install realsense2: The following packages have unmet dependencies: libgtk-3-dev
MapReduce&Yarn理论
逻辑英语结构【重点】
druid数据源实现后台监控
QPM performance monitoring components - General
jar版本冲突问题解决
VI summary of common commands
随机推荐
爬虫相关文章收藏:pyppeteer 、Burpsuite
Install new version cmake & swig & tinyspline
SQL modification of table structure
c语言语法基础之——函数定义学习
SSM项目小例子,SSM整合图文详细教程
Control setting layout in linear layout_ Gravity doesn't work?
Wechat official account reported error 10003
logback
Problems encountered by jupyter notebook
做测试需要知道的内容——url、弱网、接口、自动化、
Day 3 array, pre post, character space, keyword and address pointer
Cloud native essay using Hana expression database service on Google kubernetes cluster
pcl install
WIN10系统实现Redis主从复制
Battery historian analyzes battery consumption
Daily-used English phrases
#云原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service
LeetCode 958. 二叉树的完全性校验
Deep learning (tentsorflow2. version) three good student performance problems (1)
Automated testing -- Introduction and example of pytest framework