2016 多校联赛7 Balls and Boxes(概率期望)
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(概率期望)的更多相关文章
- hdu-5810 Balls and Boxes(概率期望)
题目链接: Balls and Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- 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 ...
- 2016 多校联赛7 Elegant Construction
Being an ACMer requires knowledge in many fields, because problems in this contest may use physics, ...
- 2016 多校联赛7 Joint Stacks (优先队列)
A stack is a data structure in which all insertions and deletions of entries are made at one end, ca ...
- 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 ...
- 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 ...
- HDU 5810 Balls and Boxes (找规律)
Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- HDU5810 Balls and Boxes
Balls and Boxes Time Limi ...
- hdu 5810 Balls and Boxes 二项分布
Balls and Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
随机推荐
- 【Java】【2】String和List相互转换
正文: 1,String转List //常见的为逗号分隔 String str = "a,b,c"; List<String> list1 = Arrays.asLis ...
- CO15批次确定,标准的太蛋疼了
1.批次确定的配置,之前有转过,自己也动手配过,可以是可以,但是蛋疼,用户不愿意去弹出的界面选批次...2.因为这边的批次全部是按年月日+流水生成的,所以在批次确定这里就需要按照批次的号来排序选择了 ...
- 使用ajax提交form表单,包括ajax文件上传【转载】
[使用ajax提交form表单,包括ajax文件上传] 前言 转载:作者:https://www.cnblogs.com/zhuxiaojie/p/4783939.html 使用ajax请求数据,很多 ...
- 一些input用法
//设定选中范围someInput.setSelectionRange(0, 2); //只读<input type="text" value="2" r ...
- nodejs 修改端口号 process.env.PORT(window环境下)
各个环境下,nodejs设置process.env.PORT的值的命令,如下1.linux环境下: PORT= node app.js 使用上面命令每次都需要重新设置,如果想设置一次永久生效,使用下面 ...
- Java数组,导入包,foreach控制循环
总见流星过,火花转瞬逝.何时见春雨,润物细无声. 导入包,例使用Scanner工具类,需要导入包: import java.util.Scanner; ************ ********** ...
- 微信PC客户端无法发送图片,怎么解决?
今天登陆电脑的微信客户端,无法发送截图图片,该怎么办? 解决方法 1.在任务栏找到程序,右键找到设置
- Linux电源管理-Linux regulator framework概述
前言 1. 什么是regulator? regulator翻译为"调节器",分为voltage regulator(电压调节器)和current(电流调节器).一般电源 ...
- vue组件通信方式总结
对于vue来说,组件之间的消息传递是非常重要的,下面是我对组件之间消息传递的各种方式的总结,总共有8种方式. 1. props和$emit 父组件向子组件传递数据是通过prop传递的,子组件传递数据给 ...
- HashMap与TreeMap按照key和value排序
package com.sort; import java.util.ArrayList; import java.util.Collections; import java.util.Compara ...