zoukankan      html  css  js  c++  java
  • codeforces 108D Basketball Team(简单组合)

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).

    A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si — how many students who play basketball belong to this department.

    Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.

    Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.

    Input

    The first line contains three integers n, m and h (1 ≤ n ≤ 100, 1 ≤ m ≤ 1000, 1 ≤ h ≤ m) — the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.

    The second line contains a single-space-separated list of m integers si (1 ≤ si ≤ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.

    Output

    Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.

    Sample test(s)
    input
    3 2 1 2 1
    output
    1.0
    input
    3 2 1 1 1
    output
    -1.0
    input
    3 2 1 2 2
    output
    0.6666666666666667
    Note

    In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.

    In the second example, there are not enough players.

    In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.

     1 /*
     2 输入:n,m,k,
     3       a[i];
     4 正难则反!总方案数为1-C(s-a[k],n-1)/C(s-1,n-1) 
     5 */
     6 
     7 
     8 #include <stdio.h>
     9 const long long mo = 1000000007;
    10 typedef long long ll;
    11 
    12 int a[2000];
    13 int main()
    14 {
    15     int m, n, k, i, j;
    16     while (~scanf("%d%d%d", &n, &m, &k))
    17     {
    18         int s = 0;
    19         for (i = 1; i <= m; i++)
    20         {
    21             scanf("%d", &a[i]);
    22             s += a[i];
    23         }
    24         if (s < n)
    25         {
    26             printf("-1.0
    ");
    27             continue;
    28         }
    29         double ans, tmp = 1.0;
    30         int s1, s2;
    31         s1 = s - 1;
    32         s2 = s - a[k];
    33         for (i = 1; i <= n - 1; i++)
    34         {
    35             tmp = tmp * s2 / s1;
    36             s2--;
    37             s1--;
    38         }
    39         ans = 1.0 - tmp;
    40         printf("%.15f
    ", ans);
    41     }
    42 
    43     return 0;
    44 }
    View Code
  • 相关阅读:
    Spark API 之 map、mapPartitions、mapValues、flatMap、flatMapValues详解
    大三寒假生活9
    大三寒假生活8
    大三寒假生活7
    MySQL SQL DML (数据操作语言)
    MySQL JOIN
    Python 可执行对象
    Python __slots__
    Python tempfile (临时文件)
    Python 文件操作
  • 原文地址:https://www.cnblogs.com/skykill/p/3264898.html
Copyright © 2011-2022 走看看