uva 557 Burger

原题:
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

Miguel A. Revilla
1998-03-10
大意:
给你2n个人,这2n个人里面包含两个兄弟Bill和Ben。然后给你两种汉堡,每种汉堡各有n个。先给除了两兄弟意外的2*n-2个人发汉堡,除了两兄弟外,剩下的人发什么汉堡用投硬币的方式决定。最后问你两兄弟得到相同的汉堡的概率。

#include <bits/stdc++.h>

using namespace std;
//fstream in,out;
double p[50005];
int main()
{
    ios::sync_with_stdio(false);
    p[1]=1.0;
    for(int i=1;i<=50000;i++)
        p[i+1]=p[i]*(i*2-1)/(2*i);
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        cout<<fixed<<setprecision(4)<<1-p[n/2]<<endl;
    }
    return 0;
}



解答:
先直接算最后结果,想了一会就把式子列出来了。可是样例数据第三个的结果是0,说明这样做不可以= =
考虑用递推的方式实现,实在是没想出来第i项和第i-1项之间的关系。看了下别人的题解,哦。原来应该先算兄弟两个拿不同汉堡的的方法。p[i]=C(2*i-2,i-1)*pow(2,-(2*i-2))这里的i代表有2*i个人。可是算到这也没明白递推到底是什么含义,貌似是用组合数学公式推导出来的。如果有哪位高人知道递推公式的含义,请教教我,谢谢~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值