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 ...
随机推荐
- MYSQL与Navicat的连接错误问题
唱,跳,RAP,Basketball MySQL版本安装 遇到的一个坑(密码加密规则被修改导致Navicat连接不上) 众所周知,老师的一些任务,往往做起来不是很困难,只要按着步骤就可以,但是在程序的 ...
- Loading class `com.mysql.jdbc.Driver'. This is deprecated警告处理,jdbc更新处
1.报错信息是这样的; 处理:提示信息表明数据库驱动com.mysql.jdbc.Driver'已经被弃用了.应当使用新的驱动com.mysql.cj.jdbc.Driver' 所以,按照提示更改jd ...
- lgb参数及调参
1 参数含义 max_depth: 设置树的最大深度,默认为-1,即不限制最大深度,它用于限制过拟合 num_leave: 单颗树的叶子数目,默认为31 eval_metric: 评价指标,可以用lg ...
- PHP 对Memcache的使用实例
<?php //连接Memcache$mem = new Memcache;$mem->connect("localhost", 11211) or die (&quo ...
- Django-DRF组件学习-其他学习
1.认证Authentication 可以在配置文件中配置全局默认的认证方案 REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_ ...
- Neither abstinence nor excess ever renders man happy
inch.n. 英寸 courageous.adj.勇敢的 porcelain.n.瓷器 adj.脆的 inventor. n. 发明者 trivial.adj. 不重要的 grove.n.小树林,果 ...
- 【Qt开发】QT中显示图像数据
一般图像数据都是以RGBRGBRGB--字节流的方式(解码完成后的原始图像流),我说成字节流,那就表明R,G,B的值各占一个字节,在编程时表示的就是unsigned char * data. 我们先来 ...
- js if 判断的使用
!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> ...
- [19/09/18-星期三] Python中的序列
一. # 第四章 序列(视频58-76) ## 列表(list) - 列表是Python中的一个对象 - 对象(object)就是内存中专门用来存储数据的一块区域 - 之前我们学习的对象,像数值,它只 ...
- Hibernate 日期映射 条件查询
1. hql: ...and accopt_time > ?" 2. query.setDate Query query = session.createQuery(hql); int ...