设为首页 加入收藏

TOP

Codeforces 107B Basketball Team 简单概率
2015-07-20 17:46:39 来源: 作者: 【 】 浏览:2
Tags:Codeforces 107B Basketball Team 简单 概率

题目链接:点击打开链接

题意:

给定n m h

表示有m个部门,有个人现在在部门h

下面m个数字表示每个部门的人数。(包括他自己)

在这些人中随机挑选n个人,问挑出的人中存在和这个人同部门的概率是多少。

这个人一定在挑出的n个人中。

反向思考。答案是 1 - 不可能概率

不可能概率 = C(n-1, sum-1-a[h]) / C(n-1, sum-1)

发现2个组合数的分母部分相同,所以只需要把2个组合数的分子部分相除即可。


#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
       #include 
       
         using namespace std; #define N 10010 int 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; }
       
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 1741 Tree 树形DP(分治) 下一篇Codeforces 347 B Fixed Points ..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C语言中如何将结构体 (2025-12-24 22:20:09)
·纯C语言结构体成员变 (2025-12-24 22:20:06)
·C语言中,指针函数和 (2025-12-24 22:20:03)
·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)