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),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种转换是一种压缩映射 ...
随机推荐
- Android Studio中由于gradle插件版本和gradle版本对应关系导致的编译失败的问题
今天在Android Studio中导入新项目,import之后编译报错,报错信息基本都是和版本相关,查询gradle版本相关知识,了解到gradle插件版本和gradle版本有相应的匹配关系,对应如 ...
- 【python】 time模块和datetime模块详解 【转】
一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...
- 【Git】二、安装配置
一.Git安装 Linux $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \ libz-dev libssl-dev $ ap ...
- S 导入公司数据
导入公司数据,使用INSERT [Public] ConnectString=host="siebel://10.10.0.46:2321/HC_CRM/SMObjMgr_chs Conne ...
- torque
torque - 必应词典 美[tɔrk]英[tɔː(r)k] n.(使机器等旋转的)转矩 网络扭矩:扭力:力矩 变形过去分词:torqued:现在分词:torquing:第三人称单数:torques ...
- Ant+jmeter+jenkins搭建测试的持续集成
前提: Ant+jmeter 已经搭建完成并成功运行(参看ant+jmeter自动化性能测试) Jenkins在本地已经安装可运行(参看上一篇) 1.下载Jenkins安装 2.浏览器输入地址http ...
- Redhat安装python环境(readline模块)
多次尝试,发现linux下安装软件: yum install readline-devel readline patch yum update python -y # 这步很重要,修复了报错 pip3 ...
- Java 设计模式系列(十)外观模式
Java 设计模式系列(十)外观模式 门面模式(Facade):外部与一个子系统的通信必须通过一个统一的外观对象进行,为子系统中的一组接口提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这 ...
- python 中feedParser
转载于https://www.cnblogs.com/bbn0111/p/7056366.html.学习使用 参考链接:http://blog.csdn.net/lanchunhui/article/ ...
- CentOS 最新版的下载地址 + 版本选择详解
CentOS 最新版的下载地址 + 版本选择详解 发现越来越多的机关单位.事业单位开始使用 Linux 作为主要服务器,毕竟,Linux的稳定性和高效性是众所周知的,所以我也打算把自己这一块技术加强一 ...