HDU5194 DZY Loves Balls【排列组合】

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5194

题目大意:

袋子里有N个黑球、M个白球。用1表示取出来的是黑球,0表示取出来的是白球。不放回

的从袋子里取出这N+M个球。求相邻取出的两个球第一个球白球,第二个球是黑球的期望

次数是多少,即出现"01"的期望次数是多少。

思路:

考虑期望可加。第i(1<=i<=N+M)个位置上出现白球的概率为M/(M+N),则i+1个位置上

出现黑球的概率为N/(M+N-1)。因为白球只能在1~M+N-1个位置上出现(后边还有黑球)。

所以出现"01"的次数为(M+n-1)次。则总的期望 = M/(M+N) * N/(M+N-1) * (M+N-1),

即M*N/(M+N)。最后求M*N和M+N的最大公约数,将分子分母约分后输出就可以了。

AC代码:

#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,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;
}
时间: 2024-08-02 15:01:04

HDU5194 DZY Loves Balls【排列组合】的相关文章

hdu5194 DZY Loves Balls 【概率论 or 搜索】

//yy:那天考完概率论,上网无聊搜个期望可加性就搜到这题,看到以后感觉特别亲和,挺有意思的. hdu5194 DZY Loves Balls [概率论 or 搜索] 题意: 一个盒子里有n个黑球和m个白球[n,m≤12].每次随机从盒子里取走一个球,取了n+m次后,刚好取完.现在用一种方法生成了一个随机的01串S[1-(n+m)],如果第i次取出的球是黑色的,那么S[i]=1,如果是白色的,那么S[i]=0.求'01'在S串中出现的期望次数. 题解: 求出在第i个位置上出现0,第i+1个位置上

Hdoj 5194 DZY Loves Balls 【打表】+【STL】

DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 394    Accepted Submission(s): 221 Problem Description There are n black balls and m white balls in the big box. Now, DZY starts

hdu-5645 DZY Loves Balls(水题)

题目链接: DZY Loves Balls Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 105    Accepted Submission(s): 75 Problem Description DZY loves playing balls. He has n balls in a big box. On each ball

hdu 5194 DZY Loves Balls

Problem Description There are n black balls and m white balls in the big box.Now, DZY starts to randomly pick out the balls one by one. It forms a sequence S. If at the i-th operation, DZY takes out the black ball, Si=1, otherwise Si=0.DZY wants to k

HDU 5194 DZY Loves Balls(概率)

Problem Description: There are n black balls and m white balls in the big box. Now, DZY starts to randomly pick out the balls one by one. It forms a sequence S. If at the i-th operation, DZY takes out the black ball, Si=1, otherwise Si=0. DZY wants t

HDU-5194-DZY Loves Balls(BestCoder Round # 35 )

DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 374    Accepted Submission(s): 205 Problem Description There are n black balls and m white balls in the big box. Now, DZY starts

BestCoder Round #35(DZY Loves Balls-暴力dp)

DZY Loves Balls Accepts: 371 Submissions: 988 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description There are n  black balls and m  white balls in the big box. Now, DZY starts to randomly pick out the ba

排列&组合

What's the Difference? In English we use the word "combination" loosely, without thinking if the order of things is important. In other words: "My fruit salad is a combination of apples, grapes and bananas" We don't care what order the

hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序

DZY Loves Topological Sorting Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5195 Description A topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for ev