zoukankan      html  css  js  c++  java
  • 朋友

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/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 is669 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

    题意:

    题意:

    一年有n天,你要找你的朋友来参加party,求至少有两个人生日相同的概率大于等于0.5时你要邀请的最少人数‘

    分析:

        求至少有两个人生日相同的情况实在有很多,所以我们逆向思维,求出任意两个人生日都不相同的概率,当达到要求是就退出循环,算的的结果就是最小人数,要注意的是我们这里要减去自己。

        打表

    #include<iostream>
    using namespace std;
    int p(int n)                             //打表
    {
    	int m=0,i=0;
         double ans=1.0;
       while(1.0-ans<0.5)
       {
    	ans*=(double)(n-i)/n;
    	m++;
    	i++;
       }
    return m;
    }
    int main()
    {
      int t,n,c=0;
      cin>>t;
      while(t--)
      {      c++;
    	  	 cin>>n;
           cout<<"Case "<<c<<": "<<p(n)-1<<endl;
      } 
      return 0;
    }
  • 相关阅读:
    Linux数据备份
    eclipse 中使用等宽字体 inconsolata
    在ubuntu14.04 64位中使用jd-gui
    Fragment 常见问题
    ClassNotFoundException
    符号表的简单使用
    一个简单的词法分析器
    一个简单的语法分析器(后缀式转换)
    火狐无法显示图片
    ftp 匿名访问设置
  • 原文地址:https://www.cnblogs.com/fenhong/p/4750382.html
Copyright © 2011-2022 走看看