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 ...
随机推荐
- Java总结第一次//有些图片未显示,文章包含基础java语言及各种语句
一.java入门 1.Java入门学习框架: 2.常用的DOS命令: dir(directory) : 列出当前目录下的文件以及文件夹 md(make directory) : 创建目录 r ...
- XML 解析 -- IE ,Chrome
通用的method <script type="text/javascript"> //for chrome, attach method to XMLDocument ...
- 【原创】Nexus搭建Maven私服
前言: 公司一般都有个自己的私服来管理各种jar包,原因大概有这么3个,分别是: 1.有的公司不能访问外网,只能通过私服来管理jar包和插件: 2.公司网速比较慢,通过公司的私服来获取jar包比较快: ...
- 很好用的查看音频波形的软件cool edit pro
- C#:WPF绘制问题
1.问题描述:切换画笔后,鼠标呈现画笔,但绘制界面需要点击后才能绘制,体验比较差 注:如果将切换为画笔或橡皮擦的功能放在二级菜单中则无次问题 解决方法(大体如此): 1)在第三方中,先创建完绘制画面和 ...
- vi复制文字
可以对文字使用标记,在光标处使用 ma 将该行标记为a,可用`a (反引号)定位到该标记a位置,用'a (单引号)定位到该行行首. d$删除光标位置到行尾,y$取光标位置到行尾.d和y也可配合标记使用 ...
- android使用其他应用打开文件
根据文件的MIME类型来判断,手机中有哪些应用可以打开这个文件,然后把应用在弹窗列表中显示 /** * 打开文件 * * @param file */ public static void openF ...
- Linux hrtimer分析(一)
http://blog.csdn.net/angle_birds/article/details/17375883 本文分析了Linux2.6.29中hrtimer的实现. Linux2.6中实现了一 ...
- StringBuffer中的flush()方法作用
在java API1.6对flush()方法的介绍如下: 方法摘要 void close() 关闭此流,但要先刷新它. void flush() 刷新该流的 ...
- Robot Motion 分类: POJ 2015-06-29 13:45 11人阅读 评论(0) 收藏
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11262 Accepted: 5482 Descrip ...