当前位置:网站首页>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;
}边栏推荐
- Openxcap usage
- SQL modification of table structure
- The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
- Upgrade idea to 2021.2 shortcut keys
- 自动化测试——pytest本身及第三方模块介绍及使用
- Druid data source for background monitoring
- VI summary of common commands
- 自动化测试——pytest框架介绍及示例
- The basis of C language grammar -- factoring by function applet
- 2021 national vocational college skills competition (secondary vocational group) network security competition questions (1) detailed analysis tutorial
猜你喜欢

WGCLOUD的web ssh服务端口是多少

国际化配置

逻辑英语结构【重点】

How does flutter transfer parameters to the next page when switching pages?

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

Redis notes (15) - Pipeline (the client packages and sends batch commands to save network overhead)

我的创作纪念日

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

Redis novice introduction

Upgrade idea to 2021.2 shortcut keys
随机推荐
The first problem troubleshooting process of re disk
TensorFlow动态分配显存
Code statistics tools cloc and SCC
Do you know the //go: instructions in the go source code, go:linkname?
Basic grammar of C language -- pointer (character, one-dimensional array) learning
Extracting public fragments from thymeleaf
Test instructions - common interface protocol analysis
The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
Several connection query methods of SQL (internal connection, external connection, full connection and joint query)
JSP file syntax
WGCLOUD的web ssh服务端口是多少
Flutter's brain map notes are easy to find and search!
mysql 数据库字段查询区分大小写设置
libgstreamer-1.0. so. 0: cannot open shared object file: No such file or directory
美国总统签署社区安全法案以应对枪支问题
國際化配置
Redis master-slave replication in win10 system
jar版本冲突问题解决
Solution to network request crash in retrofit2.8.1
软件测试---如何选择合适的正交表