当前位置:网站首页>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;
}边栏推荐
- 我在中山,到哪里开户比较好?在线开户安全么?
- 自动化测试——pytest框架介绍及示例
- MapReduce&Yarn理论
- A concise tutorial for getting started with go generics
- Record a time when the server was taken to mine
- install ompl. sh
- c语言语法基础之——指针( 多维数组、函数、总结 ) 学习
- Openxcap usage
- Wechat official account reported error 10003
- npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead. npm ER
猜你喜欢

Several connection query methods of SQL (internal connection, external connection, full connection and joint query)

The 100000 line transaction lock has opened your eyes.

Extracting public fragments from thymeleaf

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

Wechat official account reported error 10003

力扣------从数组中移除最大值和最小值

install realsense2: The following packages have unmet dependencies: libgtk-3-dev

What you need to know to test -- URL, weak network, interface, automation

Test instructions - common interface protocol analysis

Force buckle ----- remove the maximum and minimum values from the array
随机推荐
力扣------从数组中移除最大值和最小值
LeetCode 958. Completeness checking of binary tree
c语言语法基础之——局部变量及存储类别、全局变量及存储类别、宏定义 学习
测试实践——app 测试注意点
pcl install
Redis notes (14) - persistence and data recovery (data persistence RDB and AOF, data recovery, mixed persistence)
2021 national vocational college skills competition (secondary vocational group) network security competition questions (1) detailed analysis tutorial
Solution to network request crash in retrofit2.8.1
How about the security of flush stock trading software? How to open an account in flush
MapReduce & yarn theory
SSM项目小例子,SSM整合图文详细教程
我在中山,到哪里开户比较好?在线开户安全么?
From TF 1 X to TF 2.6 (update if you encounter it)
异常记录-23
Wechat official account reported error 10003
Leetcode basic calculator 224 227. follow up 394
My creation anniversary
Vscode common programming fonts
Control setting layout in linear layout_ Gravity doesn't work?
同花顺炒股软件安全性怎样?在同花顺怎么开户