UVA 557 Burger

Source: Internet
Author: User

Original question:
Burger
When Mr and Mrs Clinton's twin sons Ben and Bill had their tenth birthday, the party is held at the McDonald ' s Restaura NT at South Broadway 202, New York. There were kids at the party, including Ben and Bill. Ronald McDonald had made hamburgers and cheeseburgers and when he served the kids he started with the girl directly Sitting left of Bill. Ben is sitting to the right of Bill. Ronald flipped A (fair) coin to decide if the girl should has a hamburger or a cheeseburger, head for hamburger, tail for Cheeseburger. He repeated this procedure with all of the other kids before serving Ben and Bill. Though, when coming to Ben he didn ' t has to flip the coin anymore because there were no cheeseburgers left, only 2 Hambur Gers.
Ronald McDonald was quite surprised this happened, so he would like to know what the probability are of this kind of events . Calculate the probability that Ben and Bill would 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 even number [2,4,6,..., 100000], which indicates the number of guests present at the party including Ben and B Ill.

Output
The output consists of n lines with all 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
Effect:
Give you a 2n person, this 2n person contains two brothers Bill and Ben. And then I'll give you two burgers, each of which has n. In addition to the two brothers accidentally 2*n-2 personal hair burger, in addition to the two brothers, the rest of the people send what burger to coin the way to decide. Finally ask you two brothers the probability of getting the same burger.

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



Answer:
First directly calculate the final result, think for a while, Bashi the child listed. However, the third result of the sample data is 0, which indicates that this cannot be done = =
Considering the implementation of recursion, I really did not think of the relationship between item I and section i-1. Look at the other people's puzzle, OH. It was supposed to be the brothers ' two ways to get a different burger. P[i]=c (2*i-2,i-1) *pow (2,-(2*i-2)) here represents a 2*i individual. But it's not clear what the meaning of recursion is, it seems to be deduced by combinatorial mathematical formula. If any man knows the meaning of the recursive formula, please teach me, thank you ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.