您的位置:首页 > 其它

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

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: