UVA 557 Burger (数学)
来源:互联网 发布:erp系统java项目 编辑:程序博客网 时间:2024/05/22 09:03
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
概率题目:将最后拿到相同的汉堡转化成拿到不同的汉堡,输出1-dp[n]即可。
考虑如下:每个事件发生概率(1/2)^(n-2)次方。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>typedef long long LL;using namespace std;const int maxn=100100;double dp[maxn];void init(){// memset(dp,0,sizeof(dp)); dp[2]=1.0; for(int i=4;i<maxn;i+=2) dp[i]=dp[i-2]*(i-3)/(i-2); // for(int i=2;i<=20;i+=2)// cout<<dp[i]<<endl;}int main(){ int n,x; init(); scanf("%d",&n); while(n--) { scanf("%d",&x); printf("%.4f\n",1.0-dp[x]); }}
- UVA 557 Burger (数学)
- uva 557 - Burger(概率)
- Uva 557 – Burger (log(x)应用 , 组合数学)
- 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 排列组合 概率
- Burger - UVa 557 概率dp
- UVa 557 - Burger(概率+递推)
- 习题10-12 UVA - 557 Burger 汉堡
- 557 - Burger(递推)
- C# 6.0 (C# vNext) 新功能之:Auto-Properties with Initializers
- windows桌面显示“系统文件夹”和“系统图标”
- DirectX11 学习笔记8 - 最简单的光照
- 仔罪作足谞着最纂鬃庄谞兹住字转
- c++____abc : a b c , ab ac ba bc ca cb, abc acb bac bca cab cba
- UVA 557 Burger (数学)
- 修改u-boot编译选项以便支持使用arm-linux-gnueabihf-编译器编译(soft-float & VFP hard)
- 关于form.submit()不能提交表单的错误原因
- Java设计模式菜鸟系列(十七)桥接模式建模与实现
- UVA 674 Coin Change (DP)
- Openwrt编译vmware镜像
- 关于C++的模板的应用(一)
- UVA 12034 Race (递推神马的)
- zoj Fire Net