Test instructions
A university has m college, each college has SI individuals, now to form a team of n people, already know the hero in the first H college, and he was first accepted by the team, now the college in the remainder of the average probability of the selection of n-1 personal
Q: The hero wants to know if there are people in the team and he is from the same college, if not enough, then output-1
This is a simple combinatorial math problem, but be aware that the intermediate process of calculation overflows.
1#include <cstdio>2 3 Const intmaxn=1010;4 #defineLL Long Long5 6 intS[MAXN];7 8 intMain ()9 {Ten intn,m,h; Onescanf"%d%d%d",&n,&m,&h); A intsum=0; - for(intI=1; i<=m;i++) - { thescanf"%d",&s[i]); -sum+=S[i]; - } - if(sum<N) + { -printf"-1\n"); + } A Else if(s[h]==1) at { -printf"0\n"); - } - Else if(sum-s[h]<n-1) - { -printf"1\n"); in } - Else to { +s[h]--; -sum--; the DoubleCnta=1; * for(LL i=sum-s[h]-n+2; i<=sum-n+1; i++) $ {Panax Notoginsengcnta*=i; - } the for(LL i=sum-s[h]+1; i<=sum;i++) + { Acnta=cnta/i; the } +printf"%.6f\n",1.0-(Double) cnta); - } $ $ return 0; -}
View Code
CF 108b Basketball team combinatorial Math