HDU 5810 Balls ans Boxes(二项分布)

Problem 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
V=∑mi=1(Xi−X¯)2m

where Xi is the number of balls in the ith box, and X¯ is the average number of balls in a box.
Your task is to find out the expected value of 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.

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.

Sample Input
2 1
2 2
0 0

Sample Output
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.

相当于扔一个球到m个盒子,重复n次。
直接套二项分布公式就出来了:

样本方差的期望 = 总体方差

公式: np(1-p)

此处p = 1/m;

ac代码:

#include 

using namespace std;

#define rep(i,a,n) for(int i = (a); i < (n); i++)
#define per(i,a,n) for(int i = (n)-1; i >= (a); i--)
#define clr(arr,val) memset(arr, val, sizeof(arr))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pi acos(-1)
typedef pair<int, int> pii;
typedef long long LL;
const int maxn = 1006;
const double eps = 1e-8;
const int mod = 1000000007;

int main(int argc, char const *argv[]) {
    LL n, m;
    while (cin >> n >> m && n && m) {
        LL g = __gcd(n*(m-1), m*m);
        cout << n*(m-1)/g << "/" << m*m/g << endl;
    }
    return 0;
}

你可能感兴趣的:(=====数学=====,数学知识)