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;
    }
  • 相关阅读:
    使用MacPorts配置PHP开发环境(PHP54+PHP FPM+NGINX+MYSQL55)
    freebsd make 常用命令(非原创)
    可以通过以下步骤生成一个简单的证书:
    Javascript相关的一些碎裂的记忆
    中兴EBG2100路由器固件
    一些javascript内容
    freebsd 记事之PHP环境搭建
    vue3 中使用 vite 时的报错
    Vite2.0 按需引入Element Plus
    移动端横屏
  • 原文地址:https://www.cnblogs.com/fenhong/p/4750382.html
Copyright © 2011-2022 走看看