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 ...
随机推荐
- json校验
直接百度:json在线解析 或 json.cnhttp://json.cn/ json格式校验的.这个更加简洁些.
- Bind[Exclude|Include]排除字段或只允许字段验证
public ActionResult xx([Bind(Exclude = "id")] xxModel xx, HttpPostedFileBase file)//排除id验证 ...
- Hibernate,JPA注解@PrimaryKeyJoinColumn
一对一(One-to-one),主键关联 用例代码如下: 数据库DDL语句 1,CAT表 create table CAT ( id CHAR) not null, create_time ), up ...
- js词法作用域规则
function foo() {console.log( a ); // 2不是3} function bar() {var a = 3;foo();} var a = 2;bar(); js中的作用 ...
- [ios][opengles]OpenGL ES基础知识简介
参考: http://www.cnblogs.com/shangdahao/archive/2011/11/05/2233587.html 3D变换:模型,视图,投影与Viewport: http:/ ...
- 限制Input输入类型的常见代码集合
搜集整理常见的限制INPUT输入类型的实现方式: 1.只能输入和粘贴汉字 <input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g ...
- 浪首登录浮层增加收藏入口项目学到的几点知识-IE7 bug、relatedTarget、字符串换行
这两天做这个项目略有收获,记录如下: 1. 项目中有个bug,在IE7中登录成功时下拉菜单没有展开的情况下总有个残影在页面中,如下图所示: 通过多种方法都没有解决,后来才知道原来是在IE中displa ...
- HttpConnection方式访问网络
参考疯狂android讲义,重点在于学习1.HttpConnection访问网络2.多线程下载文件的处理 主activity: package com.example.multithreaddownl ...
- 默认调用电脑IE版本最高版本
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
- 翻译之basename()
NAME top basename, dirname - parse pathname components SYNOPSIS top #include <libgen.h> char * ...
Where
is the number of balls in the ith box, and
is the average number of balls in a box.