0
点赞
收藏
分享

微信扫一扫

LightOJ 1104 - Birthday Paradox【概率】

灯火南山 2023-03-03 阅读 65


题目链接:​​http://www.lightoj.com/volume_showproblem.php?problem=1104​​​
题意:生日驳论,求最小满足条件的人数
代码:

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <ctype.h>
#include <time.h>
#include <queue>
#include <map>
#include <set>

using namespace std;

int t;
int n;
int dp[100010];

int main()
{
cin >> t;
for (int ca = 1; ca <= t; ca++)
{
memset(dp,0,sizeof(dp));
cin >> n;
cout << "Case " << ca << ": ";
if (n == 1)
cout << 1 << endl;
else
{
double ans = 1.0;
int i;
for ( i = 1; i <= n; i++)
{
ans *= ((n - i)*1.0 / n);
if (ans <= 0.5)
break;
}
cout << i << endl;
}
}
return 0;
}


举报

相关推荐

0 条评论