博客
关于我
HDU 5194 DZY Loves Balls
阅读量:437 次
发布时间:2019-03-06

本文共 1932 字,大约阅读时间需要 6 分钟。

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. (
TestCase150
)
The first line contains two integers, 
n
m(1n,m12)
 

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/5            Hint    Case 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
 
题目大意:
给你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
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define MAX 0x3f3f3f3f#define MIN -0x3f3f3f3f#define PI 3.14159265358979323#define N 1005int 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;}

转载地址:http://fojyz.baihongyu.com/

你可能感兴趣的文章
Mysql 拼接多个字段作为查询条件查询方法
查看>>
mysql 排序id_mysql如何按特定id排序
查看>>
Mysql 提示:Communication link failure
查看>>
mysql 插入是否成功_PDO mysql:如何知道插入是否成功
查看>>
Mysql 数据库InnoDB存储引擎中主要组件的刷新清理条件:脏页、RedoLog重做日志、Insert Buffer或ChangeBuffer、Undo Log
查看>>
mysql 数据库中 count(*),count(1),count(列名)区别和效率问题
查看>>
mysql 数据库备份及ibdata1的瘦身
查看>>
MySQL 数据库备份种类以及常用备份工具汇总
查看>>
mysql 数据库存储引擎怎么选择?快来看看性能测试吧
查看>>
MySQL 数据库操作指南:学习如何使用 Python 进行增删改查操作
查看>>
MySQL 数据库的高可用性分析
查看>>
MySQL 数据库设计总结
查看>>
Mysql 数据库重置ID排序
查看>>
Mysql 数据类型一日期
查看>>
MySQL 数据类型和属性
查看>>
mysql 敲错命令 想取消怎么办?
查看>>
Mysql 整形列的字节与存储范围
查看>>
mysql 断电数据损坏,无法启动
查看>>
MySQL 日期时间类型的选择
查看>>
Mysql 时间操作(当天,昨天,7天,30天,半年,全年,季度)
查看>>