LightOj_1104 Birthday Paradox
题意:
若一年有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的更多相关文章
- Codeforces 711E ZS and The Birthday Paradox
传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st ...
- 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 ...
- 教程-(SQL DBE、ADO连接)+(Firebird火鸟+DbExpress)+(VF DBF数据库)+(DB Paradox)
DBE 连接SQL Server显然用ADO或DBEXPRESS更有优势,起码连接起来比较方便. BDE的话可以用如下方法:(以下以Delphi7为例,其它版本的DELPHI请自己摸索一下,不过基本相 ...
- 数学概念——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) ...
- Barber paradox
According to Wikipedia, the well known barber paradox states like this: The barber is the "one ...
- Codeforces 711E ZS and The Birthday Paradox 数学
ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...
- 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 ...
- C# 连接Paradox DB
Paradox数据库是一个成名于15年前的数据库,那时候Borland公司还存在.最近客户提出需求,要在一套用了12年+的应用程序上作些功能更改.这套应用程序使用Delphi+Paradox数据库. ...
随机推荐
- 关于XCode5打开工程闪退的一种解决方案
今天同事遇到一个问题,是关于xcode5打开工程文件一直闪退的问题.后来查看了一下崩溃日志.有如下描述: xception Type: EXC_CRASH (SIGABRT) Exception Co ...
- The content of element type "beans" must match "(description?,(import|alias|bean)*)
The content of element type "beans" must match "(description?,(import|alias|bean)*) - ...
- asp.net网站性能优化2则
摘要:Web服务器的性能优化有很多资料介绍了,多台主机负载均衡,查询结果的多级缓 存,数据库索引优化等都是常见的优化手段.随着后端优化空间越来越小,现在越来越多 的网站更注重前端性能的优化,就是浏览器 ...
- PHP+jQuery+Ajax实现用户登录与退…
用户登录与退出功能应用在很多地方,而在有些项目中,我们需要使用Ajax方式进行登录,登录成功后只刷新页面局部,从而提升了用户体验度.本文将使用PHP和jQuery来实现登录和退出功能. 查看演示DEM ...
- getSharedPreferences()与getSharedPreferences()与getDefaultSharedPreferences()的区别
http://blog.csdn.net/ah200614435/article/details/7869681 一直迷惑于这三个方法的关系,最近忙完项目,好好的分析一下. 如果你熟悉Context那 ...
- Android Studio美化之优雅的logcat
博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园: 追风917 先来个图,图样吐sexy: 很简单,跟我走吧,两步: 1. 引入Logger库 首先,这个sexy ...
- sql - 查询所有表中包含指定值
可以直接创建sql语句: CREATE TABLE qResults (tName nvarchar(370), cname nvarchar(3630),[count] int) declare @ ...
- 2013年10月13日学习:SQL通过图形化界面创建表
通过SQL2005创建表的方式有两种: 1.通过图形化用户界面来创建表.比较容易出问题,不稳定,容易点错了.不推荐 2.通过命令来创建.大牛都是这样做的,比较好. 通过图形化界面创建:以创建员工表为例 ...
- DataList分页-增加自动编号列
<asp:DataList ID="dl_XUDAXIA" runat="server"> <HeaderTemplate> <t ...
- window.event对象详细介绍
1.event代表事件的状态,例如触发event对象的元素.鼠标的位置及状态.按下的键等等.event对象只在事件发生的过程中才有效.event的某些属性只对特定的事件有意义.比如,fromEleme ...