Balls and Boxes

                                                                           Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
                                                                                                 Total Submission(s): 797    Accepted Submission(s): 526

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(Xi−X¯)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
—————————————————————————————————
题意:把n个球放到m个盒子里面,求上面这个式子的期望;
思路:打表找规律,发现答案=n*(m-1)/m*m 求gcd即可
证明:

E(V)=1/m*E(∑(xi-x)2)=E((x-n/m)2)=E(x2)-2*n/m*E(x)+n2/m2
E(x)=n/m;E(x2)=D(x)+[E(x)]2;变成二项分布了,D(x)=n*(m-1)/m2
所以带到上面的式子中就变成了E(v)=n*(m-1)/m2

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; LL n,m; LL gcd(LL x,LL y)
{
return x?gcd(y%x,x):y;
} int main()
{
while(~scanf("%lld%lld",&n,&m)&&(n+m))
{
if(m==1) {printf("0/1\n");continue;}
n=(m-1)*n;
m=m*m;
printf("%lld/%lld\n",n/gcd(n,m),m/gcd(n,m));
}
return 0;
}

HDU5810 Balls and Boxes的更多相关文章

  1. hdu-5810 Balls and Boxes(概率期望)

    题目链接: Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/O ...

  2. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  3. Codeforces Round #158 (Div. 2) C. Balls and Boxes 模拟

    C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. HDU 5810 Balls and Boxes (找规律)

    Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  5. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  6. Codeforces 260C - Balls and Boxes

    260C - Balls and Boxes 思路:模拟.在x前面找到最小值,如果没有,从0跳到n,继续找到最小值,边找最小值路过的点边减1.然后所有值都减去最小值,最小值那个点加上减去的值. 找到x ...

  7. hdu 5810 Balls and Boxes 二项分布

    Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  8. 2016 多校联赛7 Balls and Boxes(概率期望)

    Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. ...

  9. 【HDU 5810多校】Balls and Boxes(打表/数学)

    1.打表找规律,下面是打表程序: #include <iostream> #include <cstdio> #define ll long long #define N 10 ...

随机推荐

  1. Mysql数据库左外连接,右外连接,模糊查询

    内连接,左外连接,右外连接都是数据库的常用连接与使用手段 内连接 select * from assets_car c inner join category c on a.id = c.id; 左外 ...

  2. CentOS 7 安装MongoDB

    一.安装 1.进入网址 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ 按照官方指南进行安装 2.创建文件 / ...

  3. JS解决在提交form表单时某个值不存在 alter弹窗点确定不刷新界面

    <form action="" method="post" onsubmit="return checkname()"> < ...

  4. 【redis 学习系列】安装-配置-卸载Redis

    一.安装 wget http://download.redis.io/releases/redis-3.0.7.tar.gz tar -zxf redis-.tar.gz ln -s redis- r ...

  5. crm开发之用户重置密码

    重置 密码这这功能. 我是没有在,stark组件中. 内置的.所以需要,自己进行定制.也就只是,在已有的增删改查的基础上,再增加一条url  和相对应的  视图函数. 好的是, 我已经预留了,增加的接 ...

  6. jquery 全选、反选、获取值、背景行、隔行变色和鼠标略过变色变色全特效

    好久没有写东西了,当然不是没东西可写,只是没有时间写.今天抽出点时间来把我最近使用的一些 Javascript 特效的东西贴出来,供自己或者别人查询使用.最近我在做一个新的 B/S 系统,由于没有专门 ...

  7. jquery.validate 远程验证remote使用详解

    目的: 试了一下远程验证,试了好几次,得出小结,可以记录下,提醒以防绕路. ----------------直接贴图,省事明了---------------- 1.引用js 2.demo的html & ...

  8. 新手必备的Linux知识

    测试人员为什么学习linux? 对于软件测试人员来说,我们测试的任何产品都是基于操作系统.比如我们每天都在使用的QQ软件,它有windows.ios.Android.Mac OS等版本,需要把QQ安装 ...

  9. Visual Studio Code 如何将新项目发布到GIT服务器

    1.在VSCode中新建或打开未添加源码管理的文件夹 2.按Ctrl+Shift+G切换到"源控件"视图,点击右上方的[初始化储存库]按钮 3.输入消息内容,然后点击右上方的[提交 ...

  10. 服务管理之openssh

    1. 使用 SSH 访问远程命令行 1.1 OpenSSH 简介 OpenSSH这一术语指系统中使用的Secure Shell软件的软件实施.用于在远程系统上安全运行shell.如果您在可提供ssh服 ...