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. 媲美jQuery的JS框架----AngularJS(二)

    前言 对于AngularJS什么,小编在这就不多做介绍了.大家可以看小编的上一篇博客. 言归正传,小编在上一篇博客中介绍了AngularJS中的指令.表达式还有非常实用的三种服务.接下来,带大家看一看 ...

  2. 微软Tech Summit 2017,微软携手Unity打造MR之夜

    2017年10月31日至11月3日,微软将在北京举办Tech Summit 2017技术暨生态大会.今年的大会不仅有大咖级人物带来的十二大主题.百余场课程,而且还会迎来最特别的一位嘉宾--微软公司首席 ...

  3. Java基础——数据类型

    Java中与C++的区别: 1.Java中没有无符号类型. 2.整型值和布尔值之间不能进行相互转换. 3.Java中不区分变量的定义和声明. 如:在C++中int i = 10;是一个定义,而exte ...

  4. TIDB技术文档翻译

    http://blog.csdn.net/antony9118/article/details/60470115

  5. Java求555 555的约数中最大的三位数。

    package org.llh.test; /** * 求555 555的约数中最大的三位数 * @author llh * */ public class Car { //整数j除以整数i(i≠0) ...

  6. 一场围绕着‘Deeping Learning’的高考

    Deep Learning的基本思想和方法 实际生活中,人们为了解决一个问题,如对象的分类(对象可是是文档.图像等),首先必须做的事情是如何来表达一个对象,即必须抽取一些特征来表示一个对象,如文本的处 ...

  7. struts2运行过程(图解)

    .................................................................................................... ...

  8. ArrayBuffer and Base64

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  9. 淘宝联盟api调用笔记

    一.流程及主要请求接口 每日凌晨1点开始,服务器定时自动请求淘宝联盟数据,请求完毕之后,执行一个存储过程对数据进行整理,删除过期...购买数量<...的商品......,请求接口分别有(tbk_ ...

  10. Java微信公众平台开发_06_素材管理

    一.本节要点 1.官方文档的media 这个media可以理解为文件,即我们需要以POST方式提交一个文件 2.媒体文件有效期 媒体文件在微信后台保存时间为3天,即3天后media_id失效. 二.代 ...