• HDU 5810 Balls and Boxes(盒子与球)


    HDU 5810 Balls and Boxes盒子与球

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

     

    Description

    题目描述

    Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he throws n balls into m boxes in such a manner that each ball has equal probability of going to each boxes. After the experiment, he calculated the statistical variance V asWhere  is the number of balls in the ith box, and  is the average number of balls in a box.

    Your task is to find out the expected value of V.

    Chopsticks先生突然对随机现象来了兴趣,还做了个实验来研究随机性。实验中,他将n个球等概率丢进m个盒子里。然后,他用下面的式子计算方差V

    表示第i个盒子中球的数量,表示每个盒子中球的平均数。

    你的任务就是找出V的期望。

     

    Input

    输入

    The input contains multiple test cases. Each case contains two integers n and m (1 <= n, m <= 1000 000 000) in a line.

    The input is terminated by n = m = 0.

    多组测试用例。每个测试用例有一行两个整数n和m(1 <= n, m <= 1000 000 000)。

    n = m = 0 时,输入结束。

     

     

    Output

    输出

    For each case, output the result as A/B in a line, where A/B should be an irreducible fraction. Let B=1 if the result is an integer.

     

    对于每个用例,输出一行结果A/B,A/B为不可约分数。结果为整数时,令B=1。

     

     

    Sample Input - 输入样例

    Sample Output - 输出样例

    2 1
    2 2
    0 0

    0/1
    1/2

     

    Hint

    提示

    In the second sample, there are four possible outcomes, two outcomes with V = 0 and two outcomes with V = 1.

     

    在第二个样例中,有4种可能结果,两种V = 0和一种V = 1。

    【题解】

    类似二项分布的实验,得到所有可能的方差,再对方差取期望……等等,这不就是求二项分布的方差吗?(脑子一抽:所有可能 + 取期望 = 等概率)

    二项分布D(X) = np(1-p)

    p = 1/m 带入D(X) 得 

    【代码 C++】

     

     1 #include <cstdio>
     2 __int64 GCD(__int64 a, __int64 b){
     3     __int64 c;
     4     while (c = a%b) a = b, b = c;
     5     return b;
     6 }
     7 int main(){
     8     __int64 n, m, g;
     9     while (scanf("%I64d%I64d", &n, &m), n + m){
    10         n *= m - 1; m *= m;
    11         g = GCD(n, m);
    12         printf("%I64d/%I64d
    ", n / g, m / g);
    13     }
    14     return 0;
    15 }


     

     

  • 相关阅读:
    JVM 垃圾收集与内存分配
    JVM 内存管理机制
    JVM 启动调优总结
    Visual Studio 2019 秘钥
    dubbo初学采坑记
    Intellij idea 一个窗口打开多模块并添加依赖
    Intellij idea 自动生成serialVersionUID
    office visio 2019 下载激活
    ASP.NET Core中的配置
    electron快捷键
  • 原文地址:https://www.cnblogs.com/Simon-X/p/5757953.html
Copyright © 2020-2023  润新知