HDU 5194 DZY Loves Balls(概率)

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

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
const int MAXN = 1000 + 10;
int n, m;
int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}
int main()
{
	while(scanf("%d%d", &n, &m)!=EOF)
	{
	    int c = gcd(n*m, n + m);
		printf("%d/%d\n", n*m/c, (n+m)/c);
	}
	return 0;
}
时间: 2024-10-12 08:33:34

HDU 5194 DZY Loves Balls(概率)的相关文章

hdu 5194 DZY Loves Balls

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 k

Hdoj 5194 DZY Loves Balls 【打表】+【STL】

DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 394    Accepted Submission(s): 221 Problem Description There are n black balls and m white balls in the big box. Now, DZY starts

hdu5194 DZY Loves Balls 【概率论 or 搜索】

//yy:那天考完概率论,上网无聊搜个期望可加性就搜到这题,看到以后感觉特别亲和,挺有意思的. hdu5194 DZY Loves Balls [概率论 or 搜索] 题意: 一个盒子里有n个黑球和m个白球[n,m≤12].每次随机从盒子里取走一个球,取了n+m次后,刚好取完.现在用一种方法生成了一个随机的01串S[1-(n+m)],如果第i次取出的球是黑色的,那么S[i]=1,如果是白色的,那么S[i]=0.求'01'在S串中出现的期望次数. 题解: 求出在第i个位置上出现0,第i+1个位置上

Codeforces 444B DZY Loves FFT(概率)

题目连接:Codeforces 444B DZY Loves FFT 题目大意:根据题目的算法生成a,b数组,然后对于每个长度的l,求a[i]*b[l-i]的最大值. 解题思路:概率问题,枚举前30大的数,如果有就可以直接输出答案,如果没有,就暴力枚举b数组为1的位置找最大值. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long

hdu-5645 DZY Loves Balls(水题)

题目链接: DZY Loves Balls Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 105    Accepted Submission(s): 75 Problem Description DZY loves playing balls. He has n balls in a big box. On each ball

hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序

DZY Loves Topological Sorting Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5195 Description A topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for ev

hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 52 Problem Description A topological sort or topological ordering of a directed

hdu.5195.DZY Loves Topological Sorting(topo排序 &amp;&amp; 贪心)

DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 866    Accepted Submission(s): 250 Problem Description A topological sort or topological ordering of a directed g

数据结构(线段树):HDU 5649 DZY Loves Sorting

DZY Loves Sorting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 294    Accepted Submission(s): 77 Problem Description DZY has a sequence a[1..n]. It is a permutation of integers 1∼n. Now he