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 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
随机推荐
- vb ——ini 配置文件
最近在学校VB 开发点小东西, 使用ini配置文件要用到下边连个函数 GetPrivateProfileString (从配置文件得到信息)百度百科的介绍http://baike.baidu.com/ ...
- 解析ECC与RECC内存之间的区分
普通的定义上区分:内存,是连接CPU 和其他设备的通道,起到缓冲和数据交换作用.当CPU在工作时,需要从硬盘等外部存储器上读取数据,但由于硬盘这个“仓库”太大,加上离CPU也很“远”,运输“原料”数据 ...
- Making your first driver - complete walkthrough(使用VisualDDK)
This article describes how to create, build and debug your first driver using Visual Studio and Visu ...
- Codeforces Round #242 (Div. 2) <A-D>
CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...
- SQL Server索引进阶:第七级,过滤的索引
原文地址: Stairway to SQL Server Indexes: Level 7,Filtered Indexes 本文是SQL Server索引进阶系列(Stairway to SQL S ...
- iOS面试题04-runtime
runtime/KVO等面试题 1.KVO内部实现原则 回答:1>KVO是基于runtime机制实现的 2>当某个类的对象第一次被观察时,系统就会在运行期动态地创建该类的一个派生类,在这个 ...
- .NET连接SAP系统专题:.NET调用RFC几种方式(一)
本来今天是要写一篇关于NCO3.0的东西,就是关乎.NET调用SAP的RFC的,支持VS2010和.NET 4.0等.现在网上到处都是充斥着NCO1.X和NCO2.0,需要用VS2003来使用,都是一 ...
- 如何在Mac系统安装eclipse并运行java程序?
链接地址:http://jingyan.baidu.com/article/7f41ecece8ef5b593c095c71.html eclipse现在也有 Mac版了,我们快来试一试吧!现在我将带 ...
- mybatis foreach where test用法
<select id="selectAny" resultType="user" parameterType="user"> s ...
- C 根据行来读取文件 字符串的截取
// TestCFile.cpp : Defines the entry point for the console application. // #include "stdafx.h&q ...