Description

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

题意:

如果一年有n天,你要找你的朋友来參加party,且要求至少有两个人生日同样的概率大于等于0.5的最少人数,这个就是你要邀请的最小人数。

思路:

求至少有两个人生日同样的情况实在有非常多。所以我们逆向思维。求出随意两个人生日都不同样的概率。当达到要求是就退出循环,算的的结果就是最小人数,要注意的是

我们这里要减去自己,应为是要邀请的人数,还要注意防止数据溢出,因此须要边乘边除。參照算法竞赛与入门经典P324-325就能解决这道题目。

代码:

  1. #include<cstdio>
  2. double birthday(int n)
  3. {
  4. double ans=1.0;
  5. int m=0;
  6. for(int i=0;; i++)
  7. {
  8. ans*=(double)(n-i)/n;
  9. m++;
  10. if(1.0-ans>=0.5)
  11. break;
  12.  
  13. }
  14. return m;
  15.  
  16. }
  17. int main()
  18. {
  19. int T,n,m;
  20. int ans;
  21. scanf("%d",&T);
  22. int test=1;
  23. while(T--)
  24. {
  25. scanf("%d",&n);
  26. ans=birthday(n)-1;
  27. printf("Case %d: %d\n",test++,ans);
  28. }
  29.  
  30. return 0;
  31. }

F - 概率(经典问题)的更多相关文章

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

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

  2. 【微信开发】PHP中奖概率经典算法实例

    $arr=array("50","30","20"); //这里简单列出三个数 $pro = array_sum($arr); // 概率数 ...

  3. Light OJ 1104 第六周F题

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

  4. GOOD BYE OI

    大米饼正式退役了,OI给我带来很多东西 我会的数学知识基本都在下面了 博客园的评论区问题如果我看到了应该是会尽力回答的... 这也是我作为一个OIer最后一次讲课的讲稿 20190731 多项式乘法 ...

  5. Python入门笔记(13):列表解析

    一.列表解析 列表解析来自函数式编程语言(haskell),语法如下: [expr for iter_var in iterable] [expr for iter_var in iterable i ...

  6. R语言︱画图

    笔者寄语:不论画啥,你先plot准没错. plot 二维坐标绘图 dotchart 点图 barplot 条形图 hist 直方图 pie 饼图 points 添加点 lines 添加线 text 添 ...

  7. matlab 常用函数

    Matlab常用函数 Matlab的内部常数  eps   浮点相对精度  pi  圆周率  exp  自然对数的底数e  i 或j  虚数单位  Inf或 inf  无穷大 Matlab概率密度函数 ...

  8. day25 面向对象继承,多态,

    这两天所学的都是面向对象,后面还有几天也是它,面向对象主要有三个大的模块,封装,继承,多态,(组合),昨天主要讲了面向对象的命名空间,还有组合的用法,今天是讲的继承还有继承里面所包括的钻石继承,以及多 ...

  9. day 7 -10 集合,文本、文件操作,函数

    day7 一.回顾 1.列表和字典在循环里边尽量不要删除元素,很麻烦 2.元组:如果元组里边只有一个逗号,且不加逗号,次元素是什么类型,就是什么类型. 二.集合 ''' 集合:可变的数据类型,它里边的 ...

随机推荐

  1. Unity 3D 的四种坐标系

    1, World Space(世界坐标): 我们在场景中添加物体(如:Cube),他们都是以世界坐标显示在场景中的.transform.position可以获得该位置坐标. 2, Screen Spa ...

  2. mysql-Innodb事务隔离级别-repeatable read详解

    http://blog.csdn.net/dong976209075/article/details/8802778 经验总结: Python使用MySQLdb数据库后,如使用多线程,每个线程创建一个 ...

  3. 【bzoj3435】[Wc2014]紫荆花之恋 替罪点分树套SBT

    题目描述 强强和萌萌是一对好朋友.有一天他们在外面闲逛,突然看到前方有一棵紫荆树.这已经是紫荆花飞舞的季节了,无数的花瓣以肉眼可见的速度从紫荆树上长了出来.仔细看看的话,这个大树实际上是一个带权树.每 ...

  4. luogu3723 [AH2017/HNOI2017]礼物 【NTT】

    题目 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度.但是在她生日的前一天, ...

  5. centos安装arm交叉工具链后常见的问题解决

    [root@localhost osdrv]# arm-hisiv400-linux-gcc -vbash: /opt/hisi-linux/x86-arm/arm-hisiv400-linux/ta ...

  6. java根据开始时间结束时间计算中间间隔日期

    public static void main(String[] args) throws Exception { String beginDate = "2016-07-16"; ...

  7. 寻找web根目录

    有时候,在利用一些命令执行漏洞时,可以以较高权限执行一些操作,但在我们想要上传shell的时候,却找不到网站根目录,下面是一些日常使用的寻找网站根目录的方法,记录下: 1.jsp 查看当前路径,在这个 ...

  8. 【bzoj3585】mex 线段树 mex,sg

    Description 有一个长度为n的数组{a1,a2,…,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. Input 第一行n,m. 第二行为n个数. 从第三行开始,每行一个询问l, ...

  9. cf 701 E - Connecting Universities

    Descrition 给你一颗\(n\le 2*10^5\)个点的树, 有\(2*k(2k\le n)\)座大学座落在点上 (任二大学不在同一个点) 求一种两两匹配的方案, 使得距离和最大 即\[ma ...

  10. 【CodeChef】PARADE(费用流,最短路)

    题意: 思路: #include<cstdio> #include<iostream> #include<algorithm> #include<cstrin ...