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仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
随机推荐
- script:查看redo产生的历史信息
script:查看redo产生的历史信息 SQL> alter session set nls_date_format='dd-mon-yy'; SQL> set lines 160 p ...
- AJAX入门---DOM操作HTML
AJAX入门---DOM操作HTML 一边学习AJAX一边坐着总结加深印象.上次写的是怎样简单的使用XMLHttpRequest对象.今天写的是DOM(文档对象模型(Document Object M ...
- Cocos2d-x layout (二)
相对某个控件进行布局 Size widgetSize = Director::getInstance()->getWinSize(); Text* alert = Text::create(&q ...
- Swift - 炫酷放射弹出按钮菜单(改造自AwesomeMenu)
这个是一个第三方按钮菜单组件,原版是使用Objective-C编写的名为AwesomeMenu的组件,地址是:https://github.com/levey/AwesomeMenu 这里改造成了Sw ...
- C语言之基本算法35—数组上三角之积 主对角之积 副对角之积
//数组算法 /* ============================================================= 题目:求四阶矩阵上三角之积.主对角之积,副对角之积: 如 ...
- [Android学习笔记]View的draw过程学习
View从创建到显示到屏幕需要经历几个过程: measure -> layout -> draw measure过程:计算view所占屏幕大小layout过程:设置view在屏幕的位置dr ...
- hdu 4970 Killing Monsters(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970 Problem Description Kingdom Rush is a popular TD ...
- [置顶] C++为什么是C++而不是++C
来自<C++ primer> 问:C++为什么是C++而不是++C 答 :C++之名是Rick Mascitti在1983年夏天定名,c说明它的本质实在C语言演化而来的,”++“是C语言的 ...
- 就是这么简单(续)!使用 RestAssuredMockMvc 测试 Spring MVC Controllers(转)
接我前面一篇文章关于RestAssured测试Restful web service的, RestAssured还有一个功能, 使用RestAssuredMockMvc 单元测试你的Spring MV ...
- ImportError: No module named _sqlite3 - 代码分享
ImportError: No module named _sqlite3 - 代码分享 ImportError: No module named _sqlite3 作者:86市场网 点击 ...