H - Birthday Paradox (生日悖论)
Sometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party where there are 23 people including you. What is the probability that at least two people in the party
have same birthday? Surprisingly the result is more than 0.5. Now here you have to do the opposite. You have given the number of days in a year. Remember that you can be in a different planet, for example, in Mars, a year is 669 days
long. You have to find the minimum number of people you have to invite in a party such that the probability of at least two people in the party have same birthday is at least 0.5.
Input starts with an integer T (≤ 20000), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 105) in a single line, denoting the number of days in a year in the planet.
For each case, print the case number and the desired result.
2
365
669
Case 1: 22
Case 2: 30
Select Code
#include <stdio.h>
#include <math.h>
int main()
{
int m,n,t,k,r;
double i; //定义double
scanf("%d",&t);
for(r=1 ; r<=t ;r++)
{
int m=1;
i=1.000;
scanf("%d",&n);
for(int j=1; ; j++)
{
i=i*(n-j)/n ;
if(i<=0.5) //这种题想明白之后其实很简单,代码不算太多,很好玩
break;
else m++;
}
printf("Case %d: %d\n",r,m); //好多题都是这种输出格式,初学者应该注意一下,下次碰到的时候} //要会用 return 0;
}
生日悖论:指如果一个房间里有23个或23个以上的人,那么至少有两个人的生日相同的概率要大于50%。这就意味着在一个典型的标准小学班级(30人)中,存在两人生日相同的可能性更高。对于60或者更多的人,这种概率要大于99%。从引起逻辑矛盾的角度来说生日悖论并不是一种悖论,从这个数学事实与一般直觉相抵触的意义上,它才称得上是一个悖论。大多数人会认为,23人中有2人生日相同的概率应该远远小于50%。



H - Birthday Paradox (生日悖论)的更多相关文章
- 【bzoj3098】Hash Killer II 生日悖论
这天天气不错,hzhwcmhf神犇给VFleaKing出了一道题:给你一个长度为N的字符串S,求有多少个不同的长度为L的子串.子串的定义是S[l].S[l + 1].… S[r]这样连续的一段.两个字 ...
- LightOj 1104 - Birthday Paradox(生日悖论概率)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1104 题意:一年365天,在有23个人的情况下,这23个人中有两个人生日相同的概率是大 ...
- Light OJ 1104 Birthday Pardo(生日悖论)
ime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Description Sometime ...
- LightOj_1104 Birthday Paradox
题目链接 题意: 若一年有n天, 问至少需要多少个人才能满足其中两个人生日相同的概率大于等于0.5? 思路: 经典问题:生日悖论 换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小 ...
- 数学概念——F 概率(经典问题)birthday paradox
F - 概率(经典问题) Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- ZS and The Birthday Paradox
ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...
- Birthday Paradox
Birthday Paradox Sometimes some mathematical results are hard to believe. One of the common problems ...
- kuangbin 带你飞 概率期望
正推不行就逆推! 经典问题:生日悖论 换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小人数. 这就是邮票收集问题的变形:每个邮票至少出现一次的概率 小于等于 0.5 邮票收集问题 ...
- 哈希(Hask)
编辑 Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种转换是一种压缩映射 ...
随机推荐
- C++Builder 也有StringBuilder
System::Sysutils::TStringBuilder *sb = new TStringBuilder; sb->Append("ww"); sb-& ...
- 【321】python进程监控:psutil
参考:Python进程监控-MyProcMonitor 参考:Python3.6 安装psutil 模块和功能简介 参考:psutil module (Download files) 参考:廖雪峰 - ...
- less gradient-vertical 方法的实现
// Vertical gradient using CSS where possible, and base64-encoded SVG for IE9 (enables use of this i ...
- 在cmd中显示mysql -uroot-proot 不是命令
这个代码的意思是打开mysql,用户名为root,密码也是root 解决办法:方法一:首先要进入mysql的bin目录下,再执行. 密码错了,重新输入密码,没有密码嘛
- Windows NT
---------siwuxie095 Windows NT,全称 Microsoft Windows New Technology (无关小贴士:NTFS 全 ...
- java 数字金额转换中文金额
public static String digitUppercase(double n){ String fraction[] = {"角", "分"}; S ...
- Docs命令大全 备用
#1 一: net use \\ip\ipc$ " " /user:" " 建立IPC空链接 net use \\ip\ipc$ "密码" ...
- vue elementui form表单验证
最近我们公司将前端框架由easyui 改为 vue+elementui .自学vue两周 就开始了爬坑之路.业余时间给大家分享一下心得,技术新手加上第一次分享(小激动),有什么不足的地方欢迎大家指正, ...
- Linux TCP拥塞控制算法原理解析
这里只是简单梳理TCP各版本的控制原理,对于基本的变量定义,可以参考以下链接: TCP基本拥塞控制http://blog.csdn.net/sicofield/article/details/9708 ...
- centos firewall-cmd常用命令
firewall-cmd --list-all firewall-cmd --zone=public --add-port=12345/tcp --permanent firewall-cmd --z ...