UVA557 LA5578 Burger概率
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA557 LA5578 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 ±0.0001 is allowed in the output due to rounding differences.
Sample Input
3
6
10
256
Sample Output
0.6250
0.7266
0.9500
问题链接:UVA557 LA5578 Burger
问题简述:(略)
问题分析:概率计算问题,不解释。解题程序来自仙客传奇团队。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA557 LA5578 Burger */
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 50000;
double p[N + 1];
int main()
p[1] = 1;
for (int i = 1; i < N; i++)
p[i + 1] = p[i] * (2 * i - 1) / (2 * i);
int t,n;
scanf("%d", &t);
while (t--)
scanf("%d", &n);
printf("%.4f\\n", 1 - p[n / 2]);
return 0;
以上是关于UVA557 LA5578 Burger概率的主要内容,如果未能解决你的问题,请参考以下文章