Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=5194
Main topic:
There are n black balls and M white balls in the bag. Using 1 means that the black ball is taken out, 0 means that the white ball is taken out. Not put back
N+m a ball out of the bag. Ask for the next two balls to be taken out of the first ball white ball, the second ball is the expectation of black ball
Number of times, i.e. what is the expected number of "01" occurrences.
Ideas:
Consider the expected additive. The probability of a white ball appearing in the 1<=i<=n+m position is M/(m+n), then the i+1 position
The probability of the black ball appearing is n/(m+n-1). Because the white ball can only appear in the 1~m+n-1 position (behind the black Ball).
So the number of occurrences of "01" is (m+n-1) times. Then the total expectation = m/(m+n) * n/(m+n-1) * (m+n-1),
That is m*n/(m+n). Finally, M*n and m+n of the greatest common divisor, the numerator of the denominator numerator after the output can be.
AC Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace Std;int GCD (int a,int b) { if (a < b) int temp = A, a = b, b = temp; if (b = = 0) return A; Return GCD (b,a%b);} int main () { int a A, B; while (Cin >> a >> b) { int fz = a*b; int fm = A+B; printf ("%d/%d\n", FZ/GCD (FZ,FM), FM/GCD (FZ,FM)); } return 0;}
HDU5194 dzy Loves Balls "permutation combination"