LightOJ1104---birthday Paradox (Birthday paradox (probability)) _ACM contest

Source: Internet
Author: User

"topic source": https://cn.vjudge.net/problem/LightOJ-1104
Meaning
The question of the birthday paradox, which describes the logical logic of the paradox, 23 people any two of the same birthday probability is 0.507, the general idea will be ridiculous.
And these are calculated by mathematical methods.
And the question is, if not on the Earth, that is, the size of a year will change, ask, no less than 0.5 of the probability, at least how many individuals on the same day birthday.
Ideas
According to Baidu Encyclopedia calculation formula:
The first person's birthday is 365, 365.
The second person's birthday is 365, 364.
The third person's birthday is 365, 363.
:
:
:
The birthday of the nth person is the 365 election 365-(n-1)
So the probability that all birthdays are different is:

So, the probability of having at least two birthdays in a person is the same:

So when n=23, the probability is 0.507.
And my method is reversed, that is, did not use 1 minus that value.
Code

 #include <iostream> using namespace std; int main () {int t,cases=1;
    cin>>t;
        while (t--) {int n;
        cin>>n;
            if (n==1) {cout<< "case" <<cases++<< ":" <<n<<endl;
        Continue
        Double Ans=1;
            for (int i=n;i>=1;i--) {ans=ans* (i*1.0)/(n*1.0);//cout<<ans<<endl; 
                if (ans<=0.5) {cout<< "case" <<cases++<< ":" <<n-i<<endl;
            Break }
        }
    }
}

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.