hdu DZY Loves Balls
2015-08-10 09:37
274 查看
期望累加性
对于第i个位置是‘0’的情况,它的概率是n/(n+m), 第i+1个位置是‘1’的情况它的概率是m/(n+m-1),然而,1出现的位置只能是1~m+n-1
所以这个概率是n/(n+m)*m/(n+m-1)*(m+n-1) --->m*n/(m+n)
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int gcd(int a, int b){
if(b == 0) return a;
return gcd(b, a%b);
}
int main(){
int n, m;
while(scanf("%d %d",&n, &m) != EOF){
int a = n+m;
int b = n * m;
int res = gcd(a, b);
printf("%d/%d\n",b/res,a/res);
}
return 0;
}
对于第i个位置是‘0’的情况,它的概率是n/(n+m), 第i+1个位置是‘1’的情况它的概率是m/(n+m-1),然而,1出现的位置只能是1~m+n-1
所以这个概率是n/(n+m)*m/(n+m-1)*(m+n-1) --->m*n/(m+n)
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int gcd(int a, int b){
if(b == 0) return a;
return gcd(b, a%b);
}
int main(){
int n, m;
while(scanf("%d %d",&n, &m) != EOF){
int a = n+m;
int b = n * m;
int res = gcd(a, b);
printf("%d/%d\n",b/res,a/res);
}
return 0;
}
相关文章推荐
- @Controller的@sessionattributes
- C++常用术语及其英文翻译的含义和简单用途总结(六)
- 计蒜客 难题题库 126 PI值计算
- 【网络协议】互联网协议入门(二)
- Hibernate调优之select new
- Oracle数据库验证连接过不去的解决办法
- iOS 定时器使用详解
- 如何使用Heartbeat,组建一个高可用性的mysql集群
- db2使用指南及dbvis使用 和db2的卸载
- enum添加到combobox和获取
- 在RESTful中,遇到400 Bad Request
- HDU 1312 Red and Black
- 【日常学习】【背包DP】codevs1155 金明的预算方案题解
- 两棵树,你砍哪一棵?
- [Hibernate系列—] 3. 映射文件和使用SchemaExport制作自己主动Schema
- Distribution money
- Clojure发音
- 计蒜客 难题题库 125 删除字母'c'
- 为github帐号添加SSH keys
- Modis水汽数据MOD05去条带和转投影的问题