Lightoj 1104-birthday Paradox (Birthday paradox probability)

Source: Internet
Author: User

Title Link: http://lightoj.com/volume_showproblem.php?problem=1104

Test instructions: 365 days a year, in the case of 23 people, two of these 23 people have the same probability of birthday is greater than 0.5;

Now on different planets for n days a year, to find X, at least x person to make two people in this x of the birthday of the same probability is >=0.5, and now in addition to their own x person, for X;

We press N = 365, then there are x individuals, the probability that these people birthdays are different is P = 1 * 364/365 * 363/365 * 362/365 * ... * (365-x)/365

Then someone's birthday the same probability is 1-p that when X >= 23 (not add themselves) 1-p>0.5, so can find out the situation of p<0.5

#include <cstring>#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<stack>#include<vector>#include<queue>using namespacestd;#defineN 105#defineMet (A, b) memset (A, B, sizeof (a))#defineMOD 110119typedefLong LongLL;intMain () {intN; intT, T =1; scanf ("%d", &T);  while(t--) {scanf ("%d", &N); Doublep =1.0; intCNT = n, ans =0;  while(P >0.5)        {            --CNT; P= p*cnt/N; Ans++; } printf ("Case %d:%d\n", t++, ans); }    return 0;}
View Code

Lightoj 1104-birthday Paradox (Birthday paradox probability)

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.