期望累加性
对于第i个位置是‘0’的情况,它的概率是n/(n+m), 第i+1个位置是‘1’的情况它的概率是m/(n+m-1),然而,1出现的位置只能是1~m+n-1
所以这个概率是n/(n+m)*m/(n+m-1)*(m+n-1) --->m*n/(m+n)
#include <iostream>
#include <string.h>#include <stdio.h>
#include <stdlib.h>
using namespace std;
int gcd(int a, int b){
if(b == 0) return a;
return gcd(b, a%b);
}
int main(){
int n, m;
while(scanf("%d %d",&n, &m) != EOF){
int a = n+m;
int b = n * m;
int res = gcd(a, b);
printf("%d/%d\n",b/res,a/res);
}
return 0;
}