点击打开链接

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

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.

Output

For each case, print the case number and the desired result.

Sample Input

2

365

669

Sample Output

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%。

先计算房间里所有人的生日都不相同的概率,那么
第一个人的生日是 365选365
第二个人的生日是 365选364
第三个人的生日是 365选363
:
:
:
第n个人的生日是 365选365-(n-1)
所以所有人生日都不相同的概率是:
那么,n个人中有至少两个人生日相同的概率就是:
所以当n=23的时候,概率为0.507
当n=100的时候,概率为0.999999692751072
对于已经确定的个人,生日不同的概率会发生变化。下面用随机变量计算:
令X[i,j]表示第i个人和第j个人生日不同的概率,则易知任意X[i,j]=364/365
令事件A表示n个人的生日都不相同
P(A)=

解P(A)<1/2,由对数可得:n>=23
相比之下,随机变量也同样的简单易懂
,且计算起来要方便得多

H - Birthday Paradox (生日悖论)的更多相关文章

  1. 【bzoj3098】Hash Killer II 生日悖论

    这天天气不错,hzhwcmhf神犇给VFleaKing出了一道题:给你一个长度为N的字符串S,求有多少个不同的长度为L的子串.子串的定义是S[l].S[l + 1].… S[r]这样连续的一段.两个字 ...

  2. LightOj 1104 - Birthday Paradox(生日悖论概率)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1104 题意:一年365天,在有23个人的情况下,这23个人中有两个人生日相同的概率是大 ...

  3. Light OJ 1104 Birthday Pardo(生日悖论)

    ime Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Description Sometime ...

  4. LightOj_1104 Birthday Paradox

    题目链接 题意: 若一年有n天, 问至少需要多少个人才能满足其中两个人生日相同的概率大于等于0.5? 思路: 经典问题:生日悖论 换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小 ...

  5. 数学概念——F 概率(经典问题)birthday paradox

    F - 概率(经典问题) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...

  6. ZS and The Birthday Paradox

    ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...

  7. Birthday Paradox

    Birthday Paradox Sometimes some mathematical results are hard to believe. One of the common problems ...

  8. kuangbin 带你飞 概率期望

    正推不行就逆推! 经典问题:生日悖论 换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小人数. 这就是邮票收集问题的变形:每个邮票至少出现一次的概率 小于等于 0.5 邮票收集问题 ...

  9. 哈希(Hask)

     编辑 Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种转换是一种压缩映射 ...

随机推荐

  1. fastjson数据格式转换 SerializerFeature属性详解

    SerializerFeature属性 名称 含义 备注 QuoteFieldNames 输出key时是否使用双引号,默认为true   UseSingleQuotes 使用单引号而不是双引号,默认为 ...

  2. 创建django的8大步骤xxx.setAttribute('name', 'user'); 添加属性和值 xxx.attr('name') 查看属性的值 $(xxx).addClass 添加样式 $().after() 添加在标签后面

    第一步.创建django 方法一:django-admin startproject 方法二: 直接在python上创建 第二步:创建工程名cmdb python manage.py startapp ...

  3. http://www.5xcg.com/bbs/forum.php?mod=viewthread&tid=51143&extra=page%3D1

    http://www.5xcg.com/bbs/forum.php?mod=viewthread&tid=51143&extra=page%3D1 因为身在酒店设备有限,只能尽量把文字 ...

  4. U3D 如何计算一个UI四个角的绝对坐标

      //方式一,使用API获取 var rtrans = gameObject.GetComponent<RectTransform>(); Vector3[] worldcorners ...

  5. 面试概率极大的Oracle存储过程

    1.什么是存储过程.存储过程是数据库服务器端的一段程序,它有两种类型.一种类似于SELECT查询,用于检索数据,检索到的数据能够以数据集的形式返回给客户.另一种类似于INSERT或DELETE查询,它 ...

  6. Oracle查看字符集

    select * from nls_database_parameters where parameter like 'NLS%CHARACTERSET';

  7. linux每天一小步---sed命令详解

    1 命令功能 sed是一个相当强大的文件处理编辑工具,sed用来替换,删除,更新文件中的内容.sed以文本行为单位进行处理,一次处理一行内容.首先sed吧当前处理的行存储在临时的缓冲区中(称为模式空间 ...

  8. intrinsicConditionQueue笔记

    一, 使用conditionQueue需要注意的一些点: 一个conditionQueue被多种Predicate condition 使用是很正常的,所以当一个wait的线程被唤醒的时候,很有可能它 ...

  9. zabbix监控cpu jumps

    cpu监控图形分为三种 cpu jumps cpu突发 包含 context switches per second 进程线程切换 interrupts per second 每秒的中断次数 cpu ...

  10. mysql查看数据库性能常用命令

    mysql> show global status; 可以列出MySQL服务器运行各种状态值,另外,查询MySQL服务器配置信息语句: mysql> show variables; 一.慢 ...