codeforces 108D Basketball Team(简单组合)
2 seconds
256 megabytes
standard input
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.
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.
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.
3 2 1 2 1
1.0
3 2 1 1 1
-1.0
3 2 1 2 2
0.6666666666666667
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.
/*
输入:n,m,k,
a[i];
正难则反!总方案数为1-C(s-a[k],n-1)/C(s-1,n-1)
*/ #include <stdio.h>
const long long mo = ;
typedef long long ll; int a[];
int main()
{
int m, n, k, i, j;
while (~scanf("%d%d%d", &n, &m, &k))
{
int s = ;
for (i = ; i <= m; i++)
{
scanf("%d", &a[i]);
s += a[i];
}
if (s < n)
{
printf("-1.0\n");
continue;
}
double ans, tmp = 1.0;
int s1, s2;
s1 = s - ;
s2 = s - a[k];
for (i = ; i <= n - ; i++)
{
tmp = tmp * s2 / s1;
s2--;
s1--;
}
ans = 1.0 - tmp;
printf("%.15f\n", ans);
} return ;
}
codeforces 108D Basketball Team(简单组合)的更多相关文章
- Codeforces 107B Basketball Team 简单概率
题目链接:点击打开链接 题意: 给定n m h 表示有m个部门,有个人如今在部门h 以下m个数字表示每一个部门的人数.(包含他自己) 在这些人中随机挑选n个人,问挑出的人中存在和这个人同部门的概率是多 ...
- find xargs 简单组合使用
简单总结下,留作自己以后拾遗...... 一.find xargs 简单组合 ## mv 小结find ./ -type f -name "*.sh"|xargs mv -t /o ...
- XKC's basketball team【线段树查询】
XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...
- [单调队列]XKC's basketball team
XKC's basketball team 题意:给定一个序列,从每一个数后面比它大至少 \(m\) 的数中求出与它之间最大的距离.如果没有则为 \(-1\). 题解:从后向前维护一个递增的队列,从后 ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team
XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...
- codeforces 57 C Array(简单排列组合)
C. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- CodeForces - 401C Team(简单构造)
题意:要求构造一个字符串,要求不能有连续的两个0在一起,也不能有连续的三个1在一起. 分析: 1.假设有4个0,最多能构造的长度为11011011011011,即10个1,因此若m > (n + ...
- Codeforces 1108D - Diverse Garland - [简单DP]
题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...
- Codeforces - 702A - Maximum Increase - 简单dp
DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforce ...
随机推荐
- 模板引擎ejs的include方法
html无法include header.ejs footer.ejs 最后用 user.ejs在首尾include
- 好书推荐:OpenSuse
现在正值暑期,有大把的空闲时间,觉得有必要好好琢磨琢磨,进一步学习认识网站相关的东东. 之前,出于某种考虑,购买了一年的搬瓦工虚拟主机(vps),每月有500G的流量.单纯使用Shadowsocks, ...
- @清晰掉 malloc是如何分配内存的?
任何一个用过或学过C的人对malloc都不会陌生.大家都知道malloc可以分配一段连续的内存空间,并且在不再使用时可以通过free释放掉.但是,许多程序员对malloc背后的事情并不熟悉,许多人甚至 ...
- 尚硅谷Docker---6-10、docker的安装
尚硅谷Docker---6-10.docker的安装 一.总结 一句话总结: docker的安装使用非常简单,安装的话yum安装epel和docker,使用的话就是docker run命令 1.doc ...
- ActiveMQ从入门到精通(二)
接上一篇<ActiveMQ从入门到精通(一)>,本篇主要讨论的话题是:消息的顺序消费.JMS Selectors.消息的同步/异步接受方式.Message.P2P/PubSub.持久化订阅 ...
- fiddler之请求过滤(Filters)
开启fiddler后,会监听所有的请求,在大多数情况下,我们只需要监听部分请求,此时可以使用Filters功能去控制. 界面显示如下: 默认情况下过滤是未开启的,需要勾选“user filters”进 ...
- USB转换PS2接线原理
https://blog.csdn.net/dfyy88/article/details/4540170 USB转换PS2接线原理 2009年09月10日 18:36:00 阅读数:13285 USB ...
- nslookup的安装方法
1.直接使用yum安装,没有找到:yum install nslookup 2.yum provides nslookup查询nslookup在哪个套件里面 3.根据上面的提示,在"*/ns ...
- 用seaborn对数据可视化
以下用sns作为seaborn的别名 1.seaborn整体布局设置 sns.set_syle()函数设置图的风格,传入的参数可以是"darkgrid", "whiteg ...
- 关于BeautifulSoup4 解析器的说明
一.解析器概述 如同前几章笔记,当我们输入: soup=BeautifulSoup(response.body) 对网页进行析取时,并未规定解析器,此时使用的是python内部默认的解析器“html. ...