博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
博客园首页新随笔联系管理订阅 随笔- 524 文章- 0 评论- 20 hdu-5810 Balls and Boxes(概率期望)...
阅读量:5230 次
发布时间:2019-06-14

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

Balls and Boxes

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

Total Submission(s): 798    Accepted Submission(s): 527

Problem Description
Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he throws n balls into m boxes in such a manner that each ball has equal probability of going to each boxes. After the experiment, he calculated the statistical variance V as
V=mi=1(XiX¯)2m
where Xi is the number of balls in the ith box, and X¯ is the average number of balls in a box.
Your task is to find out the expected value of V.
 
Input
The input contains multiple test cases. Each case contains two integers n and m (1 <= n, m <= 1000 000 000) in a line.
The input is terminated by n = m = 0.
 
Output
For each case, output the result as A/B in a line, where A/B should be an irreducible fraction. Let B=1 if the result is an integer.

 

Sample Input
2 1
2 2
0 0
 
Sample Output
0/1
1/2
 
Hint
In the second sample, there are four possible outcomes, two outcomes with V = 0 and two outcomes with V = 1.
Author
SYSU
 
Source
题解:
转自:http://blog.csdn.net/qq978874169/article/details/52165136
 

 

#include
#include
#include
using namespace std;typedef long long int ll;ll n,m;ll fenzi,fenmu;ll tmp;ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}int main(){ while(~scanf("%lld%lld",&n,&m)&&(n*m)) { fenzi=n*(m-1); fenmu=m*m; tmp=gcd(fenzi,fenmu); fenzi/=tmp; fenmu/=tmp; printf("%lld/%lld\n",fenzi,fenmu); } return 0;}

 

转载于:https://www.cnblogs.com/stepping/p/7169700.html

你可能感兴趣的文章
设计模式之桥接模式(Bridge)
查看>>
jquery的$(document).ready()和onload的加载顺序
查看>>
Python Web框架Django (五)
查看>>
.net学习之继承、里氏替换原则LSP、虚方法、多态、抽象类、Equals方法、接口、装箱拆箱、字符串------(转)...
查看>>
【codevs1033】 蚯蚓的游戏问题
查看>>
【程序执行原理】
查看>>
第二次项目冲刺(Beta阶段)5.24
查看>>
python的多行注释
查看>>
连接Oracle需要jar包和javadoc文档的下载
查看>>
UVA 10976 - Fractions Again?!
查看>>
Dreamweaver cc新版本css单行显示
查看>>
【android】安卓的权限提示及版本相关
查看>>
JavaScript可否多线程? 深入理解JavaScript定时机制
查看>>
IOS基础学习
查看>>
PHP 导出 Excell
查看>>
Java基础教程——网络基础知识
查看>>
自己到底要的是什么
查看>>
this 指向
查看>>
Kruskal基础最小生成树
查看>>
BZOJ.4819.[SDOI2017]新生舞会(01分数规划 费用流SPFA)
查看>>