2015 HUAS Summer Trainning #6~F

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

解题思路:这个题目的数学思想比较多,只要将求概率的公式求出来然后算法注意点差不多就没有问题。值得注意的一点是求出的结果要减去1,因为题目中给出的案例已经说明不包括作者本人,在第一组案例中按照公式求出的答案本来应该是23,但是输出的却是22,所以答案应该注意要减去1;还有一点需要注意的是题目中说的是至少有两人在同一天生日的概率要超过0.5,所以当概率等于0.5时还不能停下来,要继续下一组,我刚开始做的时候没有注意到这个问题所以错了一次,在while中的条件应为>0.5,而不是》=0.5.

程序代码:

#include<stdio.h>
int main()
{
	int t,i,f=0;
	double n,v,s;
	scanf("%d",&t);
	while(t--)
	{
		f++;
		v=1;
		scanf("%lf",&n);
		s=n;
		i=0;
		while(v>0.5)
		{
			v=v*(s/n);
			s--;
			i++;
		}
		printf("Case %d: %d\n",f,i-1);
	}
	return 0;
}
时间: 2024-10-08 16:18:38

2015 HUAS Summer Trainning #6~F的相关文章

2015 HUAS Summer Trainning #6~H

Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.  问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数.  给定一个区间,你能计算出这个区间内有多少个美素数吗? Input 第一行输入一个正整数T,表示总共有T组数据(T <= 10000). 接下来共T行,每行输入两个整数L,R(1<= L <= R <= 10

2015 HUAS Summer Trainning #4 C

My birthday is coming up and traditionally I’mserving pie. Not just one pie, no, I have a numberN of them, of various tastes and of various sizes. Fof my friends are coming to my party and each ofthem gets a piece of pie. This should be one pieceof o

2015 HUAS Summer Trainning #5~N

Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave … The bone collector had a big bag with a volume of V ,and

2015 HUAS Summer Trainning #6~G

Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into

2015 HUAS Summer Training#2 F

题目: Description A robot has to patrol around a rectangular area which is in a form of mxn grid (m rows and n columns). The rows are labeled from 1 to m. The columns are labeled from 1 to n. A cell (i, j) denotes the cell in row i and column j in the

2015 HUAS Summer Trainning #4 B

Description Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so calledscribers. The scriber had been given a book and after several months he finished its copy. One of

2015 HUAS Summer Trainning #4 D

Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose the minimalamount of them, such they would completely cover the segment [0, M]. InputThe first line is the number of test cases, followed by a blank line.Eac

2015 HUAS Summer Trainning #5~E

Description The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John is one of them. He is very concerned about the evolution of the stock exchange. He follows stock prices every day looking for

2015 HUAS Summer Trainning #4 A

Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input seque