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++】

 #include <cstdio>
__int64 GCD(__int64 a, __int64 b){
__int64 c;
while (c = a%b) a = b, b = c;
return b;
}
int main(){
__int64 n, m, g;
while (scanf("%I64d%I64d", &n, &m), n + m){
n *= m - ; m *= m;
g = GCD(n, m);
printf("%I64d/%I64d\n", n / g, m / g);
}
return ;
}

HDU 5810 Balls and Boxes(盒子与球)的更多相关文章

  1. HDU 5810 Balls and Boxes (找规律)

    Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  2. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  3. hdu 5810 Balls and Boxes 二项分布

    Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. HDU 5810 Balls and Boxes ——(数学,概率,方差)

    官方题解看不太懂,参考了一些人的博客以后自己证明如下: 其中D(X)和E(X)的公式如下(参考自百度百科): 其中 p = 1 / m .(这是每一个单独事件发生的概率期望,在这里单独事件指的是一个球 ...

  5. HDU 5810 Balls and Boxes

    n*(m-1)/(m*m) #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio&g ...

  6. hdu 5810:Balls and Boxes(期望)

    题目链接 这题似乎就是纯概率论.. E(V)=D(X_i)=npq (p=1/m,p+q=1) #include<bits/stdc++.h> using namespace std; t ...

  7. Codeforces Round #158 (Div. 2) C. Balls and Boxes 模拟

    C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. HDU5810 Balls and Boxes

    Balls and Boxes                                                                            Time Limi ...

  9. hdu-5810 Balls and Boxes(概率期望)

    题目链接: Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/O ...

随机推荐

  1. selenium验证码处理

    在爬虫过程中经常遇到验证码,如何处理验证码就显得很重要 现在来说貌似没有完美的解决方案,很多都是通过第三方平台来实现验证码的验证 将获取的验证码的url发送到第三方平台,接收平台返回的验证码,貌似很简 ...

  2. mirrors

    http://mirrors.163.com/http://mirrors.aliyun.com/http://mirrors.aliyun.com/centos/7.2.1511/os/x86_64 ...

  3. 关于学习keynote

    下午在学习如何用keynote写出高大上的文档,看到公司内的一个妹纸洋洋洒洒的写了好多篇文章,顿时觉得自己的知识面狭窄,文科女和理科女的差别,从我嘴里半天吐不出一个富有诗情画意的词句来,那么还是脚踏实 ...

  4. innodb double write buffer

    两次写是innodb的一个重要特性,目的是为了保证在异常down机或者没电的情况下,保证数据的安全可靠.一次是往内存的double write buffer中写,一次是在刷共享表空间的连续128个页. ...

  5. 【python cookbook】【字符串与文本】6.以不区分大小写的方式对文本做查找和替换

    问题:以不区分大小写的方式对文本做查找和替换 解决方法:使用re模块,并对各种操作都添加上re.IGNORECASE标记 text='UPPER PYTHON,lower python,Mixed P ...

  6. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on ...

  7. C#:IText构造PDF文件

    IText构造PDF文件 1.1 生成Document Document是我们要生成的PDF文件所有元素的容器,因此要生成一个PDF文档,必须首先定义一个Document对象. Document有三种 ...

  8. [STL][C++]MAP

    参考链接:http://blog.sina.com.cn/s/blog_61533c9b0100fa7w.html map头文件 #include <map> map添加数据: map&l ...

  9. ACM题目————玩转二叉树

    给定一棵二叉树的中序遍历和前序遍历,请你先将树做个镜面反转,再输出反转后的层序遍历的序列.所谓镜面反转,是指将所有非叶结点的左右孩子对换.这里假设键值都是互不相等的正整数. 输入格式: 输入第一行给出 ...

  10. 杭电1002-A + B Problem II

    #include<stdio.h>#include<string.h> int main(){    char str1[1001],str2[1001];    int t, ...