F - 概率(经典问题)

Time 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

程序分析:给你某个星球上一年的天数,求出至少有两个人生日相同的种数,且要使这种情况发生的概率最小为0.5

至少有两个人的生日相同,对立面就是任何两人的生日都不相同,求出它的概率为p,然后只要使1-p>=0.5即可

#include<iostream>
#include<cstdio>
using namespace std;
int n,t,k=;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
int total=;
double p=1.0;
for(int i=; i<n; i++)
{
p*=double(n-i)/n;
if(-p>=0.5)
break;
total++; }
printf("Case %d: %d\n",k++,total);
}
return ;
}

Light OJ 1104 第六周F题的更多相关文章

  1. light oj 1248 第六周E题(期望)

    E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Descri ...

  2. light oj 1104 Birthday Paradox (概率题)

    Sometimes some mathematical results are hard to believe. One of the common problems is the birthday ...

  3. hdu 4548 第六周H题(美素数)

    第六周H题 - 数论,晒素数 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   De ...

  4. 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)

    第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...

  5. Codeforces 559A 第六周 O题

    Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...

  6. HDU 1465 第六周L题

    Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!  做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样.  ...

  7. Light OJ 1104 Birthday Pardo(生日悖论)

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

  8. 福建工程学院寒假作业第一周F题

    Subsequence TimeLimit:1000MS  MemoryLimit:65536K 64-bit integer IO format:%lld   问题描述: A sequence of ...

  9. 概率 light oj 1104

    t个数据 n天一年  至少2个人在同一天生日的概率>=0.5 问至少多少人 显然要从反面考虑 设365天 都在不同一天的概率 p(num)=1*364/365*363/365...; =(day ...

随机推荐

  1. 用Processon在线绘制UML的尝试

    地址https://www.processon.com/ ProcessOn是一个面向垂直专业领域的作图工具和社交网络,成立于2011年6月并于2012年启动.ProcessOn将全球的专家顾问.咨询 ...

  2. 使用atomic一定是线程安全的吗

    这个问题很少遇到,但是答案当然不是.atomic在set方法里加了锁,防止了多线程一直去写这个property,造成难以预计的数值.但这也只是读写的锁定.跟线程安全其实还是差一些.看下面. @inte ...

  3. angularJS promise $q

    Promise 一 介绍 1.什么是promise 我们知道JavaScript语言的执行环境是“单线程”,所谓单线程,就是一次只能够执行一个任务,如果有多个任务的话就要排队,前面一个任务完成后才可以 ...

  4. raw_input() 与 input()的区别

    raw_input和input两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互.但他们的功能不尽相同.下面举两个例子,来说明两者 raw_input和input两个均是 pyth ...

  5. boost------bind的使用(Boost程序库完全开发指南)读书笔记

    bind是c++98标准库中函数适配器bind1st/bind2nd的泛化和增强,可以适配任意的可调用类型,包括函数指针.函数引用.成员函数指针和函数对象. 1.工作原理 bind并不是一个单独的类或 ...

  6. Go语言学习笔记(一) : 搭建Windows下的Go开发环境

    最近突然对Go语言产生了兴趣,主要是因为在使用python的时候遇到了一些不爽的问题,然后发现了Go.Go是Google出的一个动态语言,语法和C++接近,性能也非常的好,而且还支持编译成exe发布, ...

  7. Ubuntu设置环境变量的几种方法

    1.Linux的变量种类 按变量的生存周期来划分,Linux变量可分为两类: 1.1 永久的:需要修改配置文件,变量永久生效. 1.2 临时的:使用export命令声明即可,变量在关闭shell时失效 ...

  8. bitbucket/github同一站点上多个git代码仓库的ssh-key配置

    由于项目开发需要,可能多个项目都放在bitbucket或者github上面,每个项目都有独立的sshkey,这就会造成push时的系统默认取~/.ssh/id_rsa的问题. 最简单的解决方法是这样: ...

  9. Ouath协议

    OAuth是一个开放协议,允许用户让第三方应用以安全且标准的方式获取该用户在某一网站.移动或桌面应用上存储的私密的资源(如用户个人信息.照片.视频.联系人列表),而无需将用户名和密码提供给第三方应用. ...

  10. Chain of Responsibility 责任链模式

    简介 责任链模式是一种对象的行为模式.在责任链模式里,很多对象由每一个对象对其[下家]的引用而连接起来形成一条链,请求在这个链上[传递],直到链上的某一个对象决定处理此请求.发出这个请求的客户端并不知 ...