意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

poj3682 King Arthur's Birthday Celebration (概率)

来源:恒创科技 编辑:恒创科技编辑部
2024-02-04 12:11:59



King Arthur's Birthday Celebration


poj3682 King Arthur's Birthday Celebration (概率)


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 comingK-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 probabilitypthat it comes up heads and 1-pup tails. The celebration will be on going until the coin has come up heads forKtimes. 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 integerK( 0 <K≤ 1000 ) and a real numberp(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


​​POJ Founder Monthly Contest – 2008.08.31​​, Soduku@POJ




解析:ans1=k/p

ans2=k*(k+1)/p/p-k/p

代码:


#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;
}



上一篇: hdu3790 最短路径问题 (dijkstra,双关键值最短路) 下一篇: 手机怎么远程登录云服务器?