Light OJ 1104 Birthday Pardo(生日悖论)
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
程序分析:此题的大意就是如果一间屋子里有23个,那么至少有两个人的生日相同的概率超过50%,但是如果在火星他们一年是669,这样他们超过50%的概率就是30个人,我们要做的就是输入天数计算概率超过50%至少需要多少人。
这个题目利用的排序,所以如果数字一大就会益处,我这里的这个代码就比较好的考虑到了这个情况,就是边乘边除。其次一点就是开始我的主函数的是double 型结果是CE最后改成int型才过的。
程序代码:
#include<iostream>
#include<cstdio>
using namespace std;
double birthday(int n)
{
double ans=1.0;
int m=;
for(int i=; ; i++)
{
ans*=(double)(n-i)/n;
m++;
if(1.0-ans>=0.5)
break;
}
return m;
}
int main()
{
int T,m,j=;
cin>>T;
while(T--)
{ j++;
cin>>m;
int k;
k=birthday(m);
printf("Case %d: %d\n",j,k-);
}
return ;
}
Light OJ 1104 Birthday Pardo(生日悖论)的更多相关文章
- 概率 light oj 1104
t个数据 n天一年 至少2个人在同一天生日的概率>=0.5 问至少多少人 显然要从反面考虑 设365天 都在不同一天的概率 p(num)=1*364/365*363/365...; =(day ...
- Light OJ 1104 第六周F题
F - 概率(经典问题) Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descri ...
- light oj 1104 Birthday Paradox (概率题)
Sometimes some mathematical results are hard to believe. One of the common problems is the birthday ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
随机推荐
- android-数据持久化
动态文件 String FILE_NAME = "tempfile.tmp"; try { //读 FileInputStream fis = openFileInput(FILE ...
- NodeJS 从0开始
查看Node 基本配置$ npm config ls -l $npm help install将展开install的help文档 初始化目录 npm init 根据提示完成 将生成package.js ...
- linux下通过脚本实现自动重启程序的方法
无论什么程序都不可能完美无缺,理论上,任何程序都有 Core Dump 的一天,正式运营的程序,尤其是服务器程序,一旦 Core Dump ,后果不堪设想,有过服务器开发经验的朋友,一定都经历过深夜美 ...
- mysql 批量删除分区
alter table titles drop partition p01; use zabbix; mysql> source drop_par.sql [oracle@oadb mysql] ...
- perl 爬取同花顺数据
use LWP::UserAgent; use utf8; use DBI; $user="root"; $passwd='xxx'; $dbh=""; $db ...
- VM Agent 和扩展程序
VM Agent 和扩展程序 - 第 1 部分 Windows Azure基础结构服务最近宣布了一项新功能VM Agent.VMAgent是一个轻量级进程,用于启动由Microsoft或合作伙伴 ...
- Android应用开发基础篇(3)-----ListView
一.概述 ListView是一个列表显示控件,它的应用非常广泛,在很多应用程序中都可以看到它的身影,比如来电通,网易新闻等等,特别是QQ.因此非常有必要熟练掌握它. 二.要求 能够利用ListView ...
- hdu 2777(线段树)
这道题是看了别人的思路才做出来的. 刚看完这道题没什么思路,线段的长度是10^5,操作指令数是10^5,还要记录不同颜色种类数,觉着怎么写肯定都是要超时.我当时在节点里增加了一个数组记录已经出现的颜色 ...
- WebSite 文件上传Demo
知识点: 1 <!--上传文件时: 1.必须使用Post方式来提交数据 2.必须设置表单的enctype属性 3.必须在表单中包含文件域.input t ...
- 火狐浏览器开始支持3D游戏和视屏通话
最近,Mozilla发布了第22版本的火狐浏览器,这个版本增加了对3D游戏.视频通话和文件分享功能的支持.现在使用者不必下载额外的插件或者第三方软件就可以使用上面的所有特性.为了鼓励更多的开发者为火狐 ...