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<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(生日悖论)的更多相关文章

  1. 概率 light oj 1104

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

  2. Light OJ 1104 第六周F题

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

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

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

  4. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  5. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  6. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  7. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  8. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  9. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

随机推荐

  1. MYSQL @、@@、@x

    说明一: @var这种形式表示的是用户自定义的变量. 说明二: @@var这种形式表示的是系统变量.它又可以分为两种一种是全局(@@global)的一种是会话(@@session)的. 说明三: MY ...

  2. linux 6.4平台利用rman迁移oracle 11g r2数据库

    测试环境分别在虚拟机安装A,B主机 系统:linux 6.4, 数据库:oracle 11g r2 A主机:安装oracle 11g r2数据库 B主机:只安装oracle 11g r2软件 第一步, ...

  3. Effective C++学习笔记——构造/析构/拷贝运算

    条款9:决不再构造和析构过程中调用virtual函数,包括通过函数间接调用virtual函数. 应用:想在一个继承体系中,一个derived class被创建时,某个调用(例如生成相应的日志log)会 ...

  4. SMT贴片机抛料的成因和回流焊横向温差问题

    SMT贴片机抛料的主要原因分析 在SMT生产过程中,怎么控制生产成本,提高生产效率,是企业老板及工程师们很关心的事情,而这些跟SMT贴片机的抛料率有很大的联系,以下就谈谈SMT贴片机的抛料问题. 所谓 ...

  5. ArcMAp对线要素进行平滑处(打断)

    一:工具简单介绍 -- ArcMAp10.1的高级编辑工具中提供了对线/面要素进行概括/平滑处理的工具. 概括工具.平滑工具分别例如以下:(首先得开启编辑状态 --- 才干够对要素的属性进行更改).选 ...

  6. POJ3771+Prim

    最小生成树的应用 数据量小. /* Prim */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...

  7. ios7 UIScrollView 尺寸问题

    假设在UINavigationController内设置一个UIViewControlller,而UIViewController的第一个子视图是UIScrollView的话,UIScrollview ...

  8. js兼容性大全

    js有个第二定律好的属性/选择器一定不兼容/* 获取类名通用代码*/function getClassName(){ if(document.getElementsByClassName){ doso ...

  9. java内存映射文件

    内存映射文件能够让我们创建和修改大文件(大到内存无法读入得文件),对于内存映射文件,我们可以认为是文件已经全部被读入到内存当中,然后当成一个大的数字来访问,简化修改文件的代码. 1.directBuf ...

  10. News feed

    1. Level 1.0 Database Schema: a. User UserID Name Age 1 Jason 25 2 Michael 26 b. Friendship Friendsh ...