标签:
题目链接:http://lightoj.com/volume_showproblem.php?problem=1104
题意:一年365天,在有23个人的情况下,这23个人中有两个人生日相同的概率是大于 0.5 的;
现在在不同的星球上一年有n天,求出x,至少有 x 个人才能使得这 x 人中有两个人的生日相同的概率是>=0.5的;现在除了自己之外还要 x 个人,求x;
我们按 n = 365 算的话,那么有x个人,这些人生日都不相同的概率是 p = 1 * 364/365 * 363/365 * 362/365 * ... *(365-x)/365
那么有人生日相同的概率是 1-p 即当 x >= 23(不加自己)时1-p>0.5的,所以可以求出p<0.5的情况
#include <cstring> #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <stack> #include <vector> #include <queue> using namespace std; #define N 105 #define met(a, b) memset(a, b, sizeof(a)) #define MOD 110119 typedef long long LL; int main() { int n; int T, t = 1; scanf("%d", &T); while(T--) { scanf("%d", &n); double p = 1.0; int cnt = n, ans = 0; while(p > 0.5) { --cnt; p = p*cnt/n; ans++; } printf("Case %d: %d\n", t++, ans); } return 0; }
LightOj 1104 - Birthday Paradox(生日悖论概率)
标签:
原文地址:http://www.cnblogs.com/zhengguiping--9876/p/5758058.html