"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 }
}
}
}