HDU 5810 Balls and Boxes(盒子与球)

本文介绍了HDU 5810 Balls and Boxes的题目背景及解决方法,通过理解实验中球等概率分配到盒子的过程,采用二项分布原理求解方差的期望值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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", n / g, m / g);
13     }
14     return 0;
15 }


 

 

转载于:https://www.cnblogs.com/Simon-X/p/5757953.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值