博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Light OJ 1104 Birthday Pardo(生日悖论)
阅读量:4326 次
发布时间:2019-06-06

本文共 1782 字,大约阅读时间需要 5 分钟。

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

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
#include
using namespace std;double birthday(int n) { double ans=1.0; int m=0; for(int i=0; ; i++) { ans*=(double)(n-i)/n; m++; if(1.0-ans>=0.5) break; } return m; }int main(){ int T,m,j=0; cin>>T; while(T--) { j++; cin>>m; int k; k=birthday(m); printf("Case %d: %d\n",j,k-1); } return 0;}

 

转载于:https://www.cnblogs.com/yilihua/p/4741585.html

你可能感兴趣的文章
转:How to force a wordbreaker to be used in Sharepoint Search
查看>>
MySQL存储过程定时任务
查看>>
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>
设计原理+设计模式
查看>>
音视频处理
查看>>
tomcat 7服务器跨域问题解决
查看>>
前台实现ajax 需注意的地方
查看>>
Jenkins安装配置
查看>>
个人工作总结05(第二阶段)
查看>>
Java clone() 浅拷贝 深拷贝
查看>>
深入理解Java虚拟机&运行时数据区
查看>>
02-环境搭建
查看>>
spring第二冲刺阶段第七天
查看>>
搜索框键盘抬起事件2
查看>>
阿里百川SDK初始化失败 错误码是203
查看>>
透析Java本质-谁创建了对象,this是什么
查看>>
BFS和DFS的java实现
查看>>
关于jquery中prev()和next()的用法
查看>>
一、 kettle开发、上线常见问题以及防错规范步骤
查看>>