zoukankan      html  css  js  c++  java
  • BZOJ 3093: [Fdu校赛2012] A Famous Game

    3093: [Fdu校赛2012] A Famous Game

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 242  Solved: 129
    [Submit][Status][Discuss]

    Description

    Mr. B and Mr. M like to play with balls. They have many balls colored in blue and red. Firstly, Mr. B randomly picks up N balls out of them and put them into a bag. Mr. M knows that there are N+1 possible situations in which the number of red balls is ranged from 0 to N, and we assume the possibilities of the N+1 situations are the same. But Mr. M does not know which situation occurs. Secondly, Mr. M picks up P balls out of the bag and examines them. There are Q red balls and P-Q blue balls. The question is: if he picks up one more ball out of the bag, what is the possibility that this ball is red?

    Input

    Each test case contains only one line with three integers N, P and Q (2 <= N <= 100,000, 0 <= P <= N-1, 0 <= Q <= P).

    Output

     
    For each test case, display a single line containing the case number and the possibility of the next ball Mr. M picks out is red. The number should be rounded to four decimal places.

    Sample Input



    3 0 0
    4 2 1

    Sample Output


    Case 1: 0.5000
    Case 2: 0.5000

    HINT



    [Explanation] 

    For example as the sample test one, there are three balls in the bag. The possibilities of the four possible situations are all 0.25. If there are no red balls in the bag, the possibility of the next ball are red is 0. If there is one red ball in the bag, the possibility is 1/3. If there are two red balls, the possibility is 2/3. Finally if all balls are red, the possibility is 1. So the answer is 0*(1/4)+(1/3)*(1/4)+(2/3)*(1/4)+1*(1/4)=0.5.

    Source

     
    [Submit][Status][Discuss]

    题意:已知有N个球,其中K个是蓝的,其余的是红的。K的范围是0到N,并且等概率。某人从其中随机取球(不放回),现在取出了P个,其中Q个是蓝色的,求下一个球是蓝色的概率。

    今天学习的概率初等内容,然而蒟蒻的我只推出了$O(N)$的做法,式子经ZXR大佬化简后得到——$frac{q+1}{p+2}$,呵呵,怪不得时限给1s。

    1 #include <cstdio>
    2 
    3 signed main(void)
    4 {
    5     int p, q, c = 0;
    6     
    7     while (scanf("%*d%d%d", &p, &q) != EOF)
    8         printf("Case %d: %.4lf
    ", ++c, 1.0*(q+1)/(p+2));
    9 }

    @Author: YouSiki

  • 相关阅读:
    委托返回类型的协变性
    委托参数的逆变性
    单例采用双锁定技术
    Jupyter Notebook 工作空间 / 默认路径 的设置方式
    Runaway argument错误 [Overleaf: 在线Latex] [Type 3问题后续]
    [Android ADB] An auto-input method for Android and Windows
    [Latex] 所有字体embedded: Type3 PDF文档处理 / True Type转换为Type 1
    螺旋矩陣 非数组解法
    2014.9.11 Research Meeting Report
    2014.8.23 Research Meeting Report
  • 原文地址:https://www.cnblogs.com/yousiki/p/6343968.html
Copyright © 2011-2022 走看看