CodeForces 107 B.Basketball Team(水~)
2017-12-30 19:29
357 查看
Description
有m个团队,第i个团队中有ai个人,现在要从这些人中选出n个人组成一队,已知第h个团队中有一个人一定被选,问最终队伍中有不少于两个来自第h个团队的人的概率
Input
第一行三个整数n,m,h,之后输入m个整数ai表示第i个团队的人数(1≤n≤100,1≤m≤1000,1≤h≤m,1≤ai≤100)
Output
如果人数不够组队则输出−1,否则输出组成满足条件队伍的概率
Sample Input
3 2 1
2 2
Sample Output
0.666667
Solution
令s=∑i=1mai
如果s<n显然输出−1
如果s−ah<n−1则必然需要从第h个团队中选取至少两个人,答案是1
否则ans=Cn−1s−ahCn−1s−1=∏i=1n−1s−ah−n+1+is−n+i
Code
有m个团队,第i个团队中有ai个人,现在要从这些人中选出n个人组成一队,已知第h个团队中有一个人一定被选,问最终队伍中有不少于两个来自第h个团队的人的概率
Input
第一行三个整数n,m,h,之后输入m个整数ai表示第i个团队的人数(1≤n≤100,1≤m≤1000,1≤h≤m,1≤ai≤100)
Output
如果人数不够组队则输出−1,否则输出组成满足条件队伍的概率
Sample Input
3 2 1
2 2
Sample Output
0.666667
Solution
令s=∑i=1mai
如果s<n显然输出−1
如果s−ah<n−1则必然需要从第h个团队中选取至少两个人,答案是1
否则ans=Cn−1s−ahCn−1s−1=∏i=1n−1s−ah−n+1+is−n+i
Code
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<map> #include<set> #include<ctime> using namespace std; typedef long long ll; typedef pair<int,int>P; const int INF=0x3f3f3f3f,maxn=100001; int main() { int n,m,h; while(~scanf("%d%d%d",&n,&m,&h)) { int s=0,ah; for(int i=1;i<=m;i++) { int a; scanf("%d",&a); if(i==h)ah=a; s+=a; } s--;n--;ah--; if(s<n)printf("-1\n"); else if(s-ah<n)printf("1\n"); else { double ans=1; for(int i=1;i<=n;i++)ans=ans*(s-ah-n+i)/(s-n+i); ans=1.0-ans; printf("%.12f\n",ans); } } return 0; }
相关文章推荐
- codeforces 107B(Basketball Team) 组合+概率 Java
- codeforces 493 C Vasya and Basketball
- NYOJ 107 A Famous ICPC Team
- Codeforces 401C Team(贪心+暴力)
- codeforces水题100道 第十一题 Codeforces Round #143 (Div. 2) A. Team (brute force)
- nyoj 107 排序问题之A Famous ICPC Team
- 【Codeforces】School Regional Team Contest, Saratov, 2011
- Codeforces 932 E. Team Work(组合数学)
- codeforces 401C - Team
- Codeforces 490A Team Olympiad(水)
- nyoj-107-A Famous ICPC Team
- codeforces 231 A Team(水题)
- codeforces—— 490A —— Team Olympiad
- CodeForces 107 D.Crime Management(状压DP+矩阵快速幂)
- CodeForces 231 A.Team(水~)
- Problem--231A--Codeforces--Team
- Codeforces 401C Team 贪心法
- NYOJ-107 A Famous ICPC Team
- Codeforces-519C-A and B and Team Training
- 【CodeForces】932 E. Team Work