hdoj5194DZY Loves Balls
2016-03-22 15:46
267 查看
DZY Loves Balls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 801 Accepted Submission(s): 437
Problem Description
There are n black
balls and m white
balls in the big box.
Now, DZY starts to randomly pick out the balls one by one. It forms a sequence S.
If at the i-th
operation, DZY takes out the black ball, Si=1,
otherwise Si=0.
DZY wants to know the expected times that '01' occurs in S.
Input
The input consists several test cases. (TestCase≤150)
The first line contains two integers, n, m(1≤n,m≤12)
Output
For each case, output the corresponding result, the format is p/q(p and q are
coprime)
Sample Input
1 1
2 3
Sample Output
1/2
6/5
HintCase 1: S='01' or S='10', so the expected times = 1/2 = 1/2
Case 2: S='00011' or S='00101' or S='00110' or S='01001' or S='01010'
or S='01100' or S='10001' or S='10010' or S='10100' or S='11000',
so the expected times = (1+2+1+2+2+1+1+1+1+0)/10 = 12/10 = 6/5
Source
BestCoder Round #35
看输入样例发现n*m/(n+m)就交了一下AC了。贴一下官方的题解吧
考虑期望的可加性。第i(1≤i<n+m)i(1\leq
i < n+m)i(1≤i<n+m)个位置上出现0,第i+1i+1i+1个位置上出现1的概率是mn+m×nn+m−1\frac{m}{n+m}
\times \frac{n}{n+m-1}n+mm×n+m−1n,那么答案自然就是∑i=1n+m−1mn+m×nn+m−1=nmn+m\sum_{i=1}^{n+m-1}\frac{m}{n+m}
\times \frac{n}{n+m-1}=\frac{nm}{n+m}∑i=1n+m−1n+mm×n+m−1n=n+mnm
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=10010;
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
int main()
{
int n,m,i,j,k;
while(scanf("%d%d",&n,&m)!=EOF){
int x=gcd(n*m,n+m);
printf("%d/%d\n",(n*m)/x,(n+m)/(x));
}
return 0;
}
相关文章推荐
- 二进制照片转base64
- MD5+SHA+BASE64加密
- 杭电1069-Monkey and Banana
- BA
- 招聘BA
- ba
- Enterprise Vault 系列 [CA和DA] 推荐
- jar包在windows下做成bat脚本开机自启动。
- HTTP Basic Auth:BA 认证
- Amoeba在Master/Slave结构下的读写分离测试
- 利用amoeba实现mysql读写分离
- ztr loves lucky numbers(STL)
- 敏捷开发模式下的BA岗
- 蝙蝠算法_总结
- hdoj5676ztr loves lucky numbers
- 管理需求激增
- 我对IT项目需求发掘的一些思考
- IT 项目的安全需求(一)— CLASP
- IT项目的安全需求(二)— SQUARE
- Bundle Adjustment学习