3985. I guess the gift is a bag!
来源:互联网 发布:淘宝网伴娘礼服 编辑:程序博客网 时间:2024/05/17 00:10
Boss Yu said that he will give gifts to the members who passed this TJU ACM recruitment contest and I guess the gifts will be some bags.
But here comes the problem: suppose there are N people and M bags. I have K good friends among the N people. Now I want to know what’s the possibility of each of the K people can have a bag.
Can you tell me the possibility?
Input
The first line contains a single integer T represents the number of test cases, for each test case there are only three integers N, M and K(1≤K≤M≤N≤1000,T≤100000).
Output
The possibility of each of the K people can have a bag, rounded to four decimal places.
Sample Input
3
2 1 1
21 3 2
1000 500 2
Sample Output
0.5000
0.0143
0.2497
题意:给出总人数,和总的背包数,以及朋友数目,求每一个朋友都能被分到一个背包的概率。
直接做显然不行,然后就推公式啦。左边是朋友都有书包的概率。
代码:
#include <cstdio>#include <algorithm>#include <cstring>#include <iostream>#include <cmath>#include <cstdlib>using namespace std;double c(int n,int k){ double ans=1; for(int i=1;i<=k;i++) { ans*=n-i+1; ans/=i; } return ans; }int main (void){ int t; cin>>t; while(t--) { int m,n,k; scanf("%d %d %d",&n,&m,&k); printf("%.4f\n",c(n-k,m-k)/c(n,m)); } return 0;}
- 3985. I guess the gift is a bag!
- 3990 G. I guess the gift is a bag! II
- Toj 3990. I guess the gift is a bag! II
- TOJ 3990.I guess the gift is a bag! II(质因数、欧拉函数好题)
- 3989. I guess the gift is a calculator! toj
- TOJ 3984 I guess the gift is an ipad!
- Toj 3984. I guess the gift is an ipad!
- life is a gift
- Today is a gift
- The gift is the present
- China Aishang Gift Bag
- Today is a gift , that's why we call it the present!
- [2015-3-25] Everyday is a gift
- I Can Guess the Data Structure! UVA11995
- 11995 - I Can Guess the Data
- UVa11995 I Can Guess the Data Structure!
- UVA11995:I Can Guess the Data Structure
- I Can Guess the Data Structure!
- redhat/centos 搭建svn服务器环境
- GCD介绍
- Javaz整型数据类型、浮点型数据类型,取值范围
- MapReduce2.0
- 方法重载
- 3985. I guess the gift is a bag!
- GCD的常见用法
- 在C# project中添加引用的System.Configuration的过程:
- Java二维数组_三角
- 洛谷 P1082 同余方程
- 3987 D. Hacb knows the gift
- L2-001. 紧急救援(dijkstra+记录路径)
- iterm2上传下载文件
- 基于 flask 框架的模拟instagram 图片分享网站的开发 4