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 as Your task is to find out the expected value of V. |
Chopsticks先生突然对随机现象来了兴趣,还做了个实验来研究随机性。实验中,他将n个球等概率丢进m个盒子里。然后,他用下面的式子计算方差V
你的任务就是找出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 |
0/1 |
|
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(盒子与球)的更多相关文章
- HDU 5810 Balls and Boxes (找规律)
Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- HDU 5810 Balls and Boxes 数学
Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- hdu 5810 Balls and Boxes 二项分布
Balls and Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5810 Balls and Boxes ——(数学,概率,方差)
官方题解看不太懂,参考了一些人的博客以后自己证明如下: 其中D(X)和E(X)的公式如下(参考自百度百科): 其中 p = 1 / m .(这是每一个单独事件发生的概率期望,在这里单独事件指的是一个球 ...
- HDU 5810 Balls and Boxes
n*(m-1)/(m*m) #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio&g ...
- 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 ...
- 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 ...
- HDU5810 Balls and Boxes
Balls and Boxes Time Limi ...
- hdu-5810 Balls and Boxes(概率期望)
题目链接: Balls and Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
随机推荐
- mysql笔记04 MySQL高级特性
MySQL高级特性 1. 分区表:分区表是一种粗粒度的.简易的索引策略,适用于大数据量的过滤场景.最适合的场景是,在没有合适的索引时,对几个分区进行全表扫描,或者是只有一个分区和索引是热点,而且这个分 ...
- 查看lnmp 编译参数
nginx :版本/opt/local/nginx/sbin/nginx -v 编译参数:/opt/local/nginx/sbin/nginx -V apache:版本/opt/local/http ...
- DataTables使用学习记录
导入 <link rel="stylesheet" type="text/css" href="DataTables-1.10.12/media ...
- 【python cookbook】【字符串与文本】12.文本过滤和清理
问题:例如清除在web页面表单中填入了pýtĥöñis这样的文本 解决方法:str.translate()方法 s = 'p\xfdt\u0125\xf6\xf1\x0cis\tawesome\r\n ...
- 内容与Tag
由于要满足精准推送内容的需求, 我们需要将车辆型号与推送内容挂钩, 方法是, 在现有的基础上, 把所有车型, 打上Tag, 目前先打上国籍跟厂商. 在现有的VEHICLE表的基础上, 增加2个colu ...
- Bootstrap:弹出框和提示框效果以及代码展示
前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编辑功能,一般常见的主要有两种处理方式:行内编辑和弹出框编辑.在增加用户体验方面,弹出框和提示框起着重要的作用,如果你的 ...
- 如何修改ECShop发货单查询显示个数
使用ecshop的朋友都知道,商城首页调用的发货单查询,默认显示的10个.很多朋友想修改它的数量,可是在后台管理却找不到相应的地方,这个修改和显示排行榜的数量修改方法不一样.排行榜是可以在后台修改的, ...
- hashMap底层put和get方法逻辑
1.hashmap put方法的实现: public V put(K key, V value) { if (key == null) return putForNullKey(value); int ...
- 关于匿名类无法转换为object
缘由,不能在Razor中使用匿名类, 先事先封装了一个方法,用于Razor给cshtml模板返回页面. 在ashx一般处理程序中,是这样调用的 匿名类的格式如下:(只看格式,不看具体内容) 调用这样 ...
- Shredding Company
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4653 Accepted: 2675 Des ...
Where
is the number of balls in the ith box, and
is the average number of balls in a box.