Codeforces sort B basketball team simple probability

Source: Internet
Author: User

Question link: Click the open link

Question:

Given N M H

Indicates that there are m departments, and an individual is in the department H

The following M numbers indicate the number of people in each department. (Including himself)

N people are randomly selected among these people, and the probability of a person in the same department as this person is asked.

This person must be among the N people picked out.

Reverse Thinking. The answer is 1-impossible probability.

Impossible probability = C (n-1, sum-1-a [H])/C (n-1, Sum-1)

The denominator of the two combinations is the same, so you only need to divide the molecular parts of the two combinations.


#include <cstdio>#include <iostream>#include <algorithm>#include <string.h>#include <map>#include <set>using namespace std;#define N 10010int n, m, h, a[N];void solve(){    int sum = 0;    for(int i = 1; i <= m; i++) scanf("%d",&a[i]), sum += a[i];    if(sum < n){        puts("-1");return ;    }    n--;    sum--; a[h]--;    if(sum - a[h] < n){puts("1");return;}    double ans = 1.0;    double x = sum-a[h], y = sum;    for(int i = 1; i <= n; i++) {        ans *= x / y;        x--; y--;    }    printf("%.10f\n", 1.0 - ans);}int main(){    while(~scanf("%d %d %d",&n,&m,&h)){        solve();    }    return 0;}


Codeforces sort B basketball team simple probability

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.