zoukankan      html  css  js  c++  java
  • Light OJ 1104 第六周F题

    F - 概率(经典问题)
    Time 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

    程序分析:给你某个星球上一年的天数,求出至少有两个人生日相同的种数,且要使这种情况发生的概率最小为0.5

         至少有两个人的生日相同,对立面就是任何两人的生日都不相同,求出它的概率为p,然后只要使1-p>=0.5即可

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int n,t,k=1;
    int main()
    {
        cin>>t;
        while(t--)
        {
            cin>>n;
            int total=0;
            double p=1.0;
            for(int i=0; i<n; i++)
            {
                p*=double(n-i)/n;
                if(1-p>=0.5)
                    break;
                total++;
    
            }
            printf("Case %d: %d
    ",k++,total);
        }
        return 0;
    }
  • 相关阅读:
    js原生图片拼图Demo
    display:inline-block在ie7下的解决办法
    Apollo 配置中心部署注意事项
    chrony 时间同步配置
    IPv6基础介绍
    Rabbitmq 报错 nodedown
    Maven 私服你应该不陌生吧,可你会用 Artifactory 搭建吗?
    你 MySQL 中重复数据多吗,教你一招优雅的处理掉它们!
    MySQL 数据库的基本使用
    自建 yum 源
  • 原文地址:https://www.cnblogs.com/hfc-xx/p/4742267.html
Copyright © 2011-2022 走看看