Burger - UVa 557 概率dp
来源:互联网 发布:单身狗公仔淘宝 编辑:程序博客网 时间:2024/05/24 15:43
Burger
When Mr. and Mrs. Clinton's twin sons Ben and Bill had their tenth birthday, the party was held at the McDonald's restaurant at South Broadway 202, New York. There were 20 kids at the party, including Ben and Bill. Ronald McDonald had made 10 hamburgers and 10 cheeseburgers and when he served the kids he started with the girl directly sitting left of Bill. Ben was sitting to the right of Bill. Ronald flipped a (fair) coin to decide if the girl should have a hamburger or a cheeseburger, head for hamburger, tail for cheeseburger. He repeated this procedure with all the other 17 kids before serving Ben and Bill last. Though, when coming to Ben he didn't have to flip the coin anymore because there were no cheeseburgers left, only 2 hamburgers.
Ronald McDonald was quite surprised this happened, so he would like to know what the probability is of this kind of events. Calculate the probability that Ben and Bill will get the same type of burger using the procedure described above. Ronald McDonald always grills the same number of hamburgers and cheeseburgers.
Input
The first line of the input-file contains the number of problems n , followed by n times:
a line with an even number [2,4,6,...,100000], which indicates the number of guests present at the party including Ben and Bill.
Output
The output consists of n lines with on each line the probability (4 decimals precise) that Ben and Bill get the same type of burger.
Note: a variance of is allowed in the output due to rounding differences.
Sample Input
3610256
Sample Output
0.62500.72660.9500
题意:有n个小朋友分n/2个汉堡和n/2个芝士汉堡,每个人通过抛硬币决定,问最后两个人的食物是一样的概率是多少。
思路:假设答案是p,那么1-p就是前面的人正好一半是汉堡,一半是芝士汉堡。设dp[i]为前i个人食物对半分的概率。dp[2*n]=C(n,2n)*(1/2)^(2n),dp[2*n+2]=C(n+1,2*n+2)*(1/2)^(2n+2),化简后可以得到dp[i]=dp[i-2]*(i-1)/i。
AC代码如下:
#include<cstdio>#include<cstring>using namespace std;double dp[100010];int main(){ int T,t,n,i,j,k; dp[0]=1; for(i=2;i<=100000;i+=2) dp[i]=dp[i-2]*(i-1)/i; scanf("%d",&T); for(t=1;t<=T;t++) { scanf("%d",&n); printf("%.4f\n",1-dp[n-2]); }}
- Burger - UVa 557 概率dp
- UVa 557 - Burger (概率)
- uva 557 - Burger(概率)
- UVA - 557 Burger 排列组合 概率
- UVA 557 - Burger(概率 递推)
- UVa 557 - Burger(概率+递推)
- uva 557 - Burger
- UVa 557 - Burger
- uva 557 Burger
- UVa 557 - Burger
- UVa 557 - Burger
- UVA - 557 Burger
- UVA 557(p344)----Burger
- uva 557 Burger
- UVA 557 Burger (数学)
- 习题10-12 UVA - 557 Burger 汉堡
- [UVA557] Burger && 概率
- uva 1637 概率DP
- 浅谈我对机器学习的理解
- 详细的介绍!CSS3 Transitions, Transforms和Animation使用简介与应用展示
- 100-git源代码管理
- EF6.0 生成的代码中没有注释的解决方法
- Web技术基础
- Burger - UVa 557 概率dp
- 谈谈我眼中的CSDN吧
- MySQL创建用户与授权方法
- RFID第一次作业第三题
- 101-开发技巧和一些常见的问题(1)
- MFC添加右键菜单
- 黑马程序员——Java编程语言学习总结 – IO流
- HDU1856_More is better
- 向设备下载镜像提示有未知符号的调试方式