题目链接

题意:

  若一年有n天, 问至少需要多少个人才能满足其中两个人生日相同的概率大于等于0.5?

思路:

  经典问题:生日悖论

  换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小人数。

  这就是邮票收集问题的变形:每个邮票至少出现一次的概率 小于等于 0.5

  等价于:

      找到最小的n, 使得:H[n] = (n / n + (n - 1) / n + (n - 2) / n + ... + 1 / n) <= 0.5

代码:

  

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 100010
#define MAXM 380
double f[MAXN];
int n;
void init()
{
double x, y;
double m;
f[] = ;
f[] = ;
for(int i = ; i < MAXN; i ++)
{
m = i;
y = i - 1.0;
x = 1.0;
for(int j = ; j < MAXM; j ++)
{
x = x * y;
x /= m;
y --;
if(x <= 0.5)
{
f[i] = j;
break;
}
}
}
} int main()
{
int T;
int kcase = ;
init();
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
printf("Case %d: %.0lf\n", ++kcase, f[n]);
}
return ;
}

LightOj_1104 Birthday Paradox的更多相关文章

  1. Codeforces 711E ZS and The Birthday Paradox

    传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st ...

  2. codeforces 711E E. ZS and The Birthday Paradox(数学+概率)

    题目链接: E. ZS and The Birthday Paradox. time limit per test 2 seconds memory limit per test 256 megaby ...

  3. 教程-(SQL DBE、ADO连接)+(Firebird火鸟+DbExpress)+(VF DBF数据库)+(DB Paradox)

    DBE 连接SQL Server显然用ADO或DBEXPRESS更有优势,起码连接起来比较方便. BDE的话可以用如下方法:(以下以Delphi7为例,其它版本的DELPHI请自己摸索一下,不过基本相 ...

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

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

  5. ZS and The Birthday Paradox

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

  6. Barber paradox

    According to Wikipedia, the well known barber paradox states like this: The barber is the "one ...

  7. Codeforces 711E ZS and The Birthday Paradox 数学

    ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...

  8. Codeforces Round #369 (Div. 2) E. ZS and The Birthday Paradox 数学

    E. ZS and The Birthday Paradox 题目连接: http://www.codeforces.com/contest/711/problem/E Description ZS ...

  9. C# 连接Paradox DB

    Paradox数据库是一个成名于15年前的数据库,那时候Borland公司还存在.最近客户提出需求,要在一套用了12年+的应用程序上作些功能更改.这套应用程序使用Delphi+Paradox数据库. ...

随机推荐

  1. C#基础知识—父类和子类的关系

    基础知识一: using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms ...

  2. 使用QEMU调试Linux内核代码

    http://blog.chinaunix.net/uid-20729583-id-1884617.html http://www.linuxidc.com/Linux/2014-08/105510. ...

  3. hadoop错误INFO util.NativeCodeLoader - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

    报如下错误: 解决方法: 1.增加调试信息 在HADOOP_HOME/etc/hadoop/hadoop-env.sh文件中添加如下信息 2.再执行一次操作,看看报什么错误 上面信息显示,需要2.14 ...

  4. C#绘制圆形时钟

    本文由作者参考部分案例后加以修改完成: 参考链接如下: http://blog.csdn.net/xuemoyao/article/details/8001113 http://wenku.baidu ...

  5. struts2 ajax 实现方式

    在 struts2 中实现ajax,可以使用struts2-json-plugin扩展,但是返回的json字段必须都是Action中的属性,不可以随意的输出文本. 返回任意的文本有两种方式, 方法一: ...

  6. flexbox 兼容安卓4.3

                 border:1px solid red;              overflow: hidden;                           font-siz ...

  7. ubuntu 12.04 编译安装 nginx

    下载源码包 nginx 地址:http://nginx.org/en/download.html 编译前先安装两个包: 直接编译安装会碰到缺少pcre等问题,这时候只要到再安装两个包就ok sudo ...

  8. CentOS7使用Redis

    使用Python操作Redis 安装pip # yum install python-pip 升级pip # pip install --upgrade pip 安装redis-py库 # pip i ...

  9. final----这篇文章是我收获很大

    final 用于声明属性.方法和类,分别表示属性不可变,方法不可重写,类不可继承. [转]Java final 修饰符知识点总结 final从字面上理解含义为“最后的,最终的”.在Java中也同样表示 ...

  10. 关于try和finaly 里面return的问题

    首先,下面这个方法调用: public int bbb(){ if(true){ return 3; } if(true){ return 4; } return 0; } 返回的结果是 :3 可见r ...