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¯)2mV=∑i=1m(Xi−X¯)2m

where XiXi is the number of balls in the ith box, and X¯X¯ is the average number of balls in a box. 
Your task is to find out the expected value of V. 

InputThe 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. 
OutputFor 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.

概率期望问题,启发博客:http://blog.csdn.net/xzxxzx401/article/details/52167534 以下
    • 首先这是一个二项分布。对于一个盒子来说,n次实验是扔n个球,每次进入盒子概率是1/m。样本方差的期望等于总体的方差!证明爱看不看。直接的结果:E(V)=n∗(m−1)m2

    • 有不用这个性质直接推出公式的。膜大神。

      E(V)=E(∑ni=0(Xi−X¯)2)m=E(x2)−2∗nm∗E(x)+n2m2 
      E(x)=nm 
      E(x2)=D(x)+[Ex]2 
      二项分布,D(x)=n∗(m−1)m2 
      所以带到上面的式子中就变成了E(V)=n∗(m−1)m2

    • 官方题解我是看不懂。

      E[V]=E[∑mi=1(Xi−X¯)2m]=E[(Xi−X¯)2]=E[X2i−2XiX¯+X¯2] 
      =E[X2i]−2X¯E[Xi]+E[X¯2]=E[X2i]−2X¯2+X¯2=E[X2i]−n2m2 
      所以关键是要求出E[X2i]. 我们用随机变量Yj来表示第j个球是否在第i个盒子中,如果在则Yj=1,否则Yj=0. 于是 
      E[X2i]=E[(∑nj=1Yj)2]=E[∑nj=1Y2j]+2E[∑nj=1∑nk=1,k≠jYjYk]=nE[Y2j]+n(n−1)E[YjYk] 
      =nm+n(n−1)m2 
      因此, 
      E[V]=nm+n(n−1)m2−n2m2=n(m−1)m2


 #include<iostream>
#include<cstdio>
using namespace std; long long gcd(long long b,long long c)//计算最大公约数
{
return c==?b:gcd(c,b%c);
} int main()
{
long long n,m;
long long a,b;
while(~scanf("%lld%lld",&n,&m)&&(n+m))
{
a=n*(m-);
if(a==)
printf("0/1\n");
else
{
b=m*m;
long long g=gcd(a,b);
printf("%lld/%lld\n",a/g,b/g);
}
}
return ;
}

 

2016 多校联赛7 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. hdu5737(2016多校联赛第2场D)

    题意:给2组数据a和b数组,每次有2种操作:(+,l,r,x)把a数组第l个到第r个元素全置为x,(?,l,r)查询[l,r]之间哪些位置满足a[i]>=b[i](i>=l &&a ...

  3. 2016 多校联赛7 Elegant Construction

    Being an ACMer requires knowledge in many fields, because problems in this contest may use physics, ...

  4. 2016 多校联赛7 Joint Stacks (优先队列)

    A stack is a data structure in which all insertions and deletions of entries are made at one end, ca ...

  5. hdu_5810:Balls and Boxes(期望)

    这题似乎就是纯概率论.. E(V)=D(X_i)=npq (p=1/m,p+q=1) #include<bits/stdc++.h> using namespace std; typede ...

  6. hdu 5810:Balls and Boxes(期望)

    题目链接 这题似乎就是纯概率论.. E(V)=D(X_i)=npq (p=1/m,p+q=1) #include<bits/stdc++.h> using namespace std; t ...

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

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

  8. HDU5810 Balls and Boxes

    Balls and Boxes                                                                            Time Limi ...

  9. hdu 5810 Balls and Boxes 二项分布

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

随机推荐

  1. js定义类

    以下是es5标准里定义类的方法: function Point(x,y){ this.x=x; this.y=y; } Point.prototype.toString=function(){ ret ...

  2. python-day96--git版本控制

    1. 版本控制工具            - svn            - git 2.  git:软件帮助使用者进行版本的管理 3.  git 相关命令 git init #初始化 初始化后,会 ...

  3. hdu-6406-dp+ST表

    Taotao Picks Apples Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Ot ...

  4. python中列表生成式

    1.简介 列表生成式即List Comprehensions,是Python中用于创建list的生成式. 2.示例 [表达式  循环体  条件语句] #!/usr/bin/env python # - ...

  5. Python标准数据类型的二次加工

    基于类继承的原理实现: class Li(list): #继承标准数据类型 list def app(self,p_object): #派生出新的 append功能 if not isinstance ...

  6. python3使用requests模块完成get/post/代理/自定义header/自定义Cookie

    一.背景说明 http请求的难易对一门语言来说是很重要的而且是越来越重要,但对于python一是urllib一些写法不太符合人的思维习惯文档也相当难看,二是在python2.x和python3.x中写 ...

  7. Oracle awr报告生成操作步骤

    1.登录主机切换到oracle用户 ssh root@192.168.220.128 su - oracle 2.以sysdba身份登录数据库 sqlplus / as sysdba 3.执行@?/r ...

  8. Linux Shell数值比较和字符串比较及相关

    说明: 1. 把字符串当成整型进行比较,由于abcd等字符对不上0123当程序尝试去转成二进制时无法完成转换,所以用于数值比较的运算不能用于字符串比较:但是把整型当成字符串进行比较,0123这些数值完 ...

  9. CentOS配置教程

    1.配置网卡开机自动启动 查看/etc/sysconfig/network-scripts/ifcfg-eth0的初始内容: cat /etc/sysconfig/network-scripts/if ...

  10. [转]perftools查看堆外内存并解决hbase内存溢出

    最近线上运行的hbase发现分配了16g内存,但是实际使用了22g,堆外内存达到6g.感觉非常诡异.堆外内存用一般的工具很难查看,可以通过google-perftools来跟踪: http://cod ...