DZY Loves Balls

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 807    Accepted Submission(s): 439

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
Hint
Case 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
 
题目大意:
给你n个黑球,m个白球,黑球标记为1,白球标记为0,问在所有的组合当中一共出现了多少个“01”串。
解题思路:
用概率统计的角度讲,这就是一个n重的伯努利试验。首先,确定一个随机变量。
设置为Xi,则在Xi位置上出现白球,并在X(i+1)位置上出现黑球的概率是p=(m/(n+m))*(n/(n+m-1))。这就是出现01串的概率,否则其他的情况概记为q=1-p。
即Xi只有两种状态,出现01串为1,否则为0。如下图所示。

这就是一个最为简单的二项分布了,以为Xi的取值是从1-(m+n-1)的。
所以有
得E(X)=(m/(m+n))*(n/(n+m-1))*(n+m-1)=(m*n)/(m+n)。
程序里面需要求的就是m*n和m+n的最大公约数化简了。
源代码:
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<math.h>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define MAX 0x3f3f3f3f
#define MIN -0x3f3f3f3f
#define PI 3.14159265358979323
#define N 1005
int gcd(int n, int m)
{
int temp;
if (m > n)
swap(m, n);
if (m == 1 || n == 1)
return 1;
temp = n%m;
while (temp != 0)
{
n = m;
m = temp;
temp = n%m;
}
return m;
}
int main()
{
int n, m;
int num;
int nn, mm;
while (scanf("%d%d", &n, &m) != EOF)
{
nn = m*n;
mm = m + n;
num = gcd(nn, mm);
printf("%d/%d\n", nn / num, mm / num);
}
return 0;
}


HDU 5194 DZY Loves Balls的更多相关文章

  1. HDU 5645 DZY Loves Balls 水题

    DZY Loves Balls 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5645 Description DZY loves playing b ...

  2. hdu 5645 DZY Loves Balls

    DZY Loves Balls  Accepts: 659  Submissions: 1393  Time Limit: 4000/2000 MS (Java/Others)  Memory Lim ...

  3. hdoj 5194 DZY Loves Balls【规律&&gcd】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5194 题意:给你n个黑球,m个白球,每次从中随机抽取一个,如果抽到黑球记为1如果抽出来白球记为0,让你 ...

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

    //yy:那天考完概率论,上网无聊搜个期望可加性就搜到这题,看到以后特别有亲和感,挺有意思的. hdu5194 DZY Loves Balls [概率论 or 搜索] 题意: 一个盒子里有n个黑球和m ...

  5. HDU 5646 DZY Loves Partition

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5646 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  6. HDU 5646 DZY Loves Partition 数学 二分

    DZY Loves Partition 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5646 Description DZY loves parti ...

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

    DZY Loves Topological Sorting Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...

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

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

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

    DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

随机推荐

  1. 【问题排查】fastjson线上排坑记

    前言 版本上线时发现fastjson的toString方法的返回的字符串与与之前版本的toString方法返回的字符串不相同,这导致依赖toString进行md5计算所得到的结果不相同,更进一步导致其 ...

  2. JS框架设计读书笔记之-选择器引擎02

    选择器引擎涉及相关概念 概念 以Sizzle的主函数声明为例,来说明引擎的相关概念. function Sizzle(selector, context, results, seed) { //... ...

  3. OpenCV Image Watch 调试插件

    昨晚偶然发现vs2012的这个很神奇的插件,对于经常使用opencv的人来说,这个插件无疑是我们的调试神器.今天马上下载试用,感觉超级棒!~以后要想查看图像结果,不用再imshow了! Image W ...

  4. 暑假练习赛 007 E - Pairs

    E - Pairs Description standard input/outputStatements In the secret book of ACM, it’s said: “Glory f ...

  5. django 实现同一个ip十分钟内只能注册一次(redis版本)

    上一篇文章,django 实现同一个ip十分钟内只能注册一次 的时候,我们在注册的时候选择使用的使我们的数据库来报错我们的注册的ip信息,可是如果数据量大,用户多的时候,单单靠我们的数据库 来储存我们 ...

  6. 文本宽度的测量--measureText

    HTML5中的canvas提供了文字宽度的测量方法: ctx.measureText(string).width var c=document.getElementById("myCanva ...

  7. Scrum Meeting Alpha - 2

    Scrum Meeting Alpha - 2 NewTeam 2017/10/25 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 完成了大部分api的测试https://gi ...

  8. 二:SQL映射文件

    二:SQL映射文件 1.SQL映射文件: (1)mapper:映射文件的根元素节点,只有一个属性namespace(命名空间) 作用:用于区分不同的mapper全局唯一 绑定dao接口即面向接口编程, ...

  9. .NET之RabbitMQ学习笔记(二)-安装

    安装 1.安装erlang语言环境 因为rabbitmq是基于erlang进行开发,所以需要安装相应的依赖环境,学习中用到的erlang包下载地址:http://www.erlang.org/down ...

  10. Spring4 事务管理

    Spring4 事务管理 本章是Spring4 教程中的最后一章,也是非常重要的一章.如果说学习IOC是知识的入门,那学习事务管理就是知识的提升.本章篇幅可能有一丢丢长,也有一丢丢难,需要读者细细品味 ...