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 <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <map>
#include <set>
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;
}
Codeforces 107B Basketball Team 简单概率的更多相关文章
- codeforces 108D Basketball Team(简单组合)
D. Basketball Team time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Aeroplane chess(简单概率dp)
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...
- 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 - 401C Team(简单构造)
题意:要求构造一个字符串,要求不能有连续的两个0在一起,也不能有连续的三个1在一起. 分析: 1.假设有4个0,最多能构造的长度为11011011011011,即10个1,因此若m > (n + ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
- Codeforces 540D Bad Luck Island - 概率+记忆化搜索
[题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...
- Codeforces 148D Bag of mice 概率dp(水
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
随机推荐
- 一int考虑什么类型的多少字节
一int表示的字节数? 问题是,我们经常得到的答案4. 但int究竟占多少个字节,却跟你的机器环境有关. As you can see, the typical data type sizes mat ...
- Delphi面向对象设计的经验原则(61条)
(1)所有数据都应该隐藏在所在的类的内部. (2)类的使用者必须依赖类的共有接口,但类不能依赖它的使用者. (3)尽量减少类的协议中的消息. (4)实现所有类都理解的最基本公有接口[例如,拷贝操作(深 ...
- ThinkPhp学习13
原文:ThinkPhp学习13 简单登录验证 创建Login类 <?php class LoginAction extends Action { function index(){ $this- ...
- [Usaco2008 Dec]Patting Heads
It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 100,00 ...
- php获取server端mac和clientmac的地址
获取servermac <?php /** 获取网卡的MAC地址原码:眼下支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址 **/ class GetmacAddr{ var $re ...
- VC生成的DLL给QT的EXE调用时lib路径问题小结
VC生成的DLL给QT调用,有两种方式,一种是隐式调用调用(使用.lib文件方式): ① 在*.pro工程文件中添加VC生成的lib文件路径时,或者使用一个绝对路径,如: LIBS += " ...
- Threejs 的场景查看 - 几个交互事件库助你方便查看场景
Threejs 的场景查看 - 几个交互事件库助你方便查看场景 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致&q ...
- 设备管理 USB ID
发现个USB ID站点,对于做设备管理识别的小伙伴特别实用 http://www.linux-usb.org/usb.ids 附录: # # List of USB ID's # # Maintain ...
- Codeforces Round #296 (Div. 2) A. Playing with Paper
A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...
- expression:stream!=NULL
如果fopen()后返回的是NULL:就不能调用fclose()了: 用fopen()获得的文件句柄不是NULL,那么就需要用fclose()来关闭它.如果是NULL则不需要 null就表示你打开文件 ...