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仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
随机推荐
- 6.0RMB MP3所看到的……
产品篇: 偶然看到这个商品信息,作为电子开发人员,首先想到的便是采用了哪家芯片方案,怎么做到这么低的价格! 于是立刻买了一台回来,拆机如下: 成本BOM: ...
- protobuf-2.5.0.tar.gz的下载与安装
1.下载 hadoop使用protocol buffer进行通信,须要下载和安装protobuf-2.5.0.tar.gz.因为如今protobuf-2.5.0.tar.gz已经无法在官网https: ...
- mormort 土拨鼠,做后端服务那是杠杠的,基于http.sys
http.sys你可以用 mormort 土拨鼠,做后端服务那是杠杠的,基于http.sys并且还是开源的,作者天天更新代码,非常勤奋,官方论坛提问,回答也快其实,稍微看看,就能玩的挺好的
- java OOP及相关基础知识汇总(转)
OOP 对象有三个要素 behavior 接口是怎样的,有什么方法/field可以用? state 调用方法的时候,对象会有什么反应? 只有通过调用方法才能改变一个对象的state identity ...
- VCL改变主窗体的方法
使用如下语句即可Pointer((@Application.MainForm)^) := Form1; 仔细想想和Pointer((Application.MainForm)) := Form1;有什 ...
- [初探iOS开发]storyboard的使用
storyboard的目的是为了方便的设计程序view之间的关系,使得程序员把精力都放到核心业务逻辑之上.
- Android实现位图剪切
我们不能总是依赖于BitmapFactory 以下告诉大家怎么从Bitmaqp中截取某一部分创建新的Bitmap 系统会有一个默认png图片:icon.png 可是这个图片中最外层会有白色的 比較讨 ...
- Java Word Ladder(字梯)
问题: Given two words (start and end), and a dictionary, find the length of shortest transformation se ...
- Enable OWIN Cross-origin Request
微软出了一套解决方式能够解决 "同意WebAPI的 CORS 请求" http://www.asp.net/web-api/overview/security/enabling-c ...
- Android推断程序前后台状态
public class AppStatusService extends Service { private static final String TAG = "AppStatusSer ...