当前位置:网站首页>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;
}边栏推荐
- The basis of C language grammar -- function nesting, Fibonacci sum of recursive applet and factorial
- Leetcode connected to rainwater series 42 (one dimension) 407 (2D)
- TensorFlow动态分配显存
- Meaning of go runtime
- Upgrade idea to 2021.2 shortcut keys
- LeetCode 498. 对角线遍历
- How to create an IE tab in edge browser
- What you need to know to test -- URL, weak network, interface, automation
- Do you know the //go: instructions in the go source code, go:linkname?
- Redis novice introduction
猜你喜欢

Test instructions - common interface protocol analysis

What is the web SSH service port of wgcloud

Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)

Specific implementation comparison between different programming languages

國際化配置

How to create an IE tab in edge browser

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

Redis master-slave replication in win10 system
![Logical English structure [key points]](/img/4b/52a666ed01087adbc5fa4f9e1db393.png)
Logical English structure [key points]

logback
随机推荐
Automated testing -- on the coexistence of Unitest and pytest initialization
How about the security of flush stock trading software? How to open an account in flush
Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
c语言语法基础之——局部变量及存储类别、全局变量及存储类别、宏定义 学习
Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)
The basis of C language grammar -- factoring by function applet
c语言语法基础之——指针( 多维数组、函数、总结 ) 学习
Automated testing -- Introduction and example of pytest framework
How does flutter transfer parameters to the next page when switching pages?
[trajectory planning] testing of ruckig Library
Cloud native essay using Hana expression database service on Google kubernetes cluster
SSM项目小例子,SSM整合图文详细教程
Leetcode basic calculator 224 227. follow up 394
Logical English structure [key points]
Learning and understanding of thread pool (with code examples)
Mysql database field query case sensitive setting
【深度优先搜索】312.戳气球
Notes on sports planning on November 22, 2021
英语常用短语
Mysql database operation commands (constantly updated)