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. 【PowerDesigner】【2】将工具栏显示出来

    问题:我的软件一打开,没有工具栏 解决方案:Tools→Customize Menus and Tools→Palette→Close 参考文档: PowerDesigner如何将消失的工具栏显示出来 ...

  2. git merge和git rebase的区别

    git merge是用来合并两个分支的.# 将b分支合并到当前分支git merge b git cherry-pick可以选择某一个分支中的一个或几个commit(s)来进行操作.例如,假设我 们有 ...

  3. React Native之FlexBox布局

    参考原文链接:https://www.cnblogs.com/wujy/p/5841685.html 弹性盒模型(The Flexible Box Module),又叫Flexbox,意为“弹性布局” ...

  4. iOS 如何优化项目

    原文 前言 在项目业务趋于稳定的时候,开发完迭代需求后,我们可能会无所适从,进入一段空白期,但是对于攻城狮来说闲暇不是件好事,所以我们可能总想学点什么,却又没有头绪.这个时候我们就可以考虑完善和优化我 ...

  5. leetcode Most Common Word——就是在考察自己实现split

    819. Most Common Word Given a paragraph and a list of banned words, return the most frequent word th ...

  6. 关于TCP长连接和发送心跳的一些理解

    原因 TCP是一种有连接的协议,但是这个连接并不是指有一条实际的电路,而是一种虚拟的电路.TCP的建立连接和断开连接都是通过发送数据实现的,也就是我们常说的三次握手.四次挥手.TCP两端保存了一种数据 ...

  7. python javar send

    # -*- coding: utf-8 -*-import jpypeimport os.pathjarpath = os.path.join(os.path.abspath('.'), 'axja' ...

  8. TCP/IP报文 三次握手 四次挥手

    1.TCP报文格式  TCP/IP协议的详细信息参看<TCP/IP协议详解>三卷本.下面是TCP报文格式图:图1 TCP报文格式  上图中有几个字段需要重点介绍下:  (1)序号:Seq序 ...

  9. AI工具5.13

    如果想选中上面的很多图形,可以锁定不需要选择的下面的图形.选择需要锁定的对象.“对象”“锁定”“所选对象” “对象”“变换”“再次变换”快捷键“ctrl=d"一般前面有其他操作如“移动”“复 ...

  10. jquery checkbox的使用

    获取单个checkbox选中的写法: $('input:checkbox:checked').val(); $("input:[type='checkbox']:checked") ...