HDU5194 dzy Loves Balls "permutation combination"

Source: Internet
Author: User
Tags greatest common divisor

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.