您的位置:首页 > 其它

hdu DZY Loves Balls

2015-08-10 09:37 274 查看
期望累加性

对于第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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: