HDU-5194-DZY Loves Balls(BestCoder Round # 35 )
来源:互联网 发布:你见过最恐怖的事 知乎 编辑:程序博客网 时间:2024/05/21 08:36
DZY Loves Balls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 374 Accepted Submission(s): 205
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 sequenceS . 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 inS .
Now, DZY starts to randomly pick out the balls one by one. It forms a sequence
DZY wants to know the expected times that '01' occurs in
Input
The input consists several test cases. (TestCase≤150 )
The first line contains two integers,n , m(1≤n,m≤12)
The first line contains two integers,
Output
For each case, output the corresponding result, the format is p/q (p and q are coprime)
Sample Input
1 12 3
Sample Output
1/26/5HintCase 1: S='01' or S='10', so the expected times = 1/2 = 1/2Case 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
Recommend
hujie | We have carefully selected several similar problems for you: 5197 5196 5195 5193 5192
BestCoder解析:
Problem A - DZY Loves Balls考虑期望的可加性。第i(1≤i<n+m) 个位置上出现0,第i+1 个位置上出现1的概率是mn+m×nn+m−1 ,那么答案自然就是∑i=1n+m−1mn+m×nn+m−1=nmn+m 如果你不能马上想到上述的简便的方法,也可以选择暴力枚举所有01串,也是可以AC的。最后一步你需要再计算一下gcd,十分简便。
n个黑球,m个白球,1表示取出的是黑球,0表示取出的是白球。
这题最好的方法就是找出题目的规律,即第i(1<=i<n+m)个位置上出现0,第i+1个位置上出现1的概率是 m/(n+m) * n/(n+m-1) .
因为要求‘01’串在S串中出现的位置,即满足这个条件,但是'0'不可以在末尾,'1'不可以在开头.对于前面n+m-1个位置都可以为0.
第i+1个位置上出现1的概率是:(出现黑球(出现1)的概率)*(出现在第i个位置上的概率)。
但是一共有n+m-1个位置上可以出现1,所以便是所有位置上的概率想加.
等价于= m/(n+m) * n/(n+m-1) * (n+m-1) = n*m/(n+m).
import java.io.*;import java.util.*;public class Main{public static void main(String[] args){Scanner input = new Scanner(System.in);while (input.hasNext()){int n = input.nextInt();int m = input.nextInt();int temp = GCD(n * m, n + m);System.out.println(n * m / temp + "/" + (n + m) / temp);}}public static int GCD(int x, int y){if (x < y)return GCD(y, x);while (x % y != 0){int temp = x % y;x = y;y = temp;}return y;}}
0 0
- HDU-5194-DZY Loves Balls(BestCoder Round # 35 )
- BestCoder Round #35(DZY Loves Balls-暴力dp)
- HDU 5194 DZY Loves Balls
- HDU 5194 DZY Loves Balls
- HDU 5194 DZY Loves Balls
- hdu 5195 DZY Loves Topological Sorting && BestCoder Round #35
- hdu 5196 DZY Loves Inversions && BestCoder Round #35
- BestCoder Round #76 (div.2) DZY Loves Balls
- hdu DZY Loves Balls
- hdu 5194 DZY Loves Balls (dp)
- HDU 5194——DZY Loves Balls
- hdu 5194 DZY Loves Balls(组合数学)
- HDU 5194 DZY Loves Balls(期望可加性)
- HDU 5194 DZY Loves Balls(概率)
- hdu 5645 DZY Loves Balls
- HDU 5645 DZY Loves Balls
- hdu 5645 DZY Loves Balls
- HDU 5645 DZY Loves Balls
- 索引内容提要(理论部分)
- Linux命令简介
- 黑马程序员---OC基础知识①
- [PAT]1002. A+B for Polynomials(25)
- 关于Activity的4种launchMode
- HDU-5194-DZY Loves Balls(BestCoder Round # 35 )
- Android 开发环境安装
- 欢迎使用CSDN-markdown编辑器
- EXCEL VBA字符串替换
- appendChild() , insertBefore()插入节点需注意的问题
- Map.Entry接口源码简析
- 数据结构顺序表定义和实现
- python MRJob
- 类名.this