Balls and Boxes

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

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
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:       
题意:给你n个球,m个盒子,每个球落入每个盒子的概率是等可能的,求方差的期望值。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x7f7f7f7f
#define FOR(i,n) for(int i=1;i<=n;i++)
#define CT continue;
#define PF printf
#define SC scanf
const int mod=1000000007;
const int N=1e3+10; ll gcd(ll a,ll b)
{
if(b==0) return a;
else return gcd(b,a%b);
} int main()
{
ll n,m;
while(~scanf("%lld%lld",&n,&m)&&(n||m))
{
ll fenzi=n*(m-1),fenmu=m*m;
while(1)
{
ll k=gcd(fenzi,fenmu);
if(k==1) break;
fenzi/=k;fenmu/=k;
}
printf("%lld/%lld\n",fenzi,fenmu);
}
return 0;
}

 分析:比赛时就感觉是个什么分布,,但是学的很多又忘了,最后百度了一下,才发现可以二项分布做;

对于每个盒子,每个球落入其中的概率是p=1/m;

那么总共n个球p(x=k)=C(n,k)*p^k*(1-p)^(n-k),显然的二项分布;

二项分布数学期望E(x)=np(n是实验次数,p是每次试验球落入盒子的概率);

方差D(x)=np(1-p)

本题中D(x)=n/m*(1-1/m)=n*(m-1)/(m^2);

 然后因为每个盒子是平等的,方差又是描述数据的混乱程度,所以多个均等的盒子的方差与单个盒子方差
是一样的

hdu 5810 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 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  3. HDU 5810 Balls and Boxes 数学

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

  4. HDU 5810 Balls and Boxes

    n*(m-1)/(m*m) #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio&g ...

  5. HDU 5810 Balls and Boxes ——(数学,概率,方差)

    官方题解看不太懂,参考了一些人的博客以后自己证明如下: 其中D(X)和E(X)的公式如下(参考自百度百科): 其中 p = 1 / m .(这是每一个单独事件发生的概率期望,在这里单独事件指的是一个球 ...

  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. HDU5810 Balls and Boxes

    Balls and Boxes                                                                            Time Limi ...

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

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

  9. 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 ...

随机推荐

  1. JavaScript的几种循环方式

    JavaScript提供了许多通过LOOPS迭代的方法.本教程解释了现代JAVASCRIPT中各种各样的循环可能性 目录: for forEach do...while while for...in ...

  2. Maven 之 profile 与Spring boot 的 profile

    一.概述 不同的环境(测试环境.开发环境)有不同的配置,目前希望在打包的时候,就直接打出针对不同环境的包(内含有某个环境的配置).Maven本身在 pom.xml 中就提供了 profile 标签进行 ...

  3. C# struct结构知识总结

    结构是一种值类型,使用struct关键字定义. 结构可以包含字段.常量.事件.属性.方法.构造函数.索引器.运算符和嵌套类型.但若结构中同时需要上述所有成员,应考虑将结构改为类. 嵌套类型:在类或构造 ...

  4. (一)初识JavaFX

    JavaFX是一个强大的图形和多媒体处理工具包集合,它允许开发者来设计.创建.测试.调试和部署富客户端程序,并且和Java一样跨平台. JavaFX应用程序 由于JavaFX库被写成了Java API ...

  5. 海量数据处理 从哈希存储到Bloom Filter(1) (转载)

    先解释一下什么是哈希函数.哈希函数简单来说就是一种映射,它可取值的范围(定义域)通常很大,但值域相对较小.哈希函数所作的工作就是将一个很大定义域内的值映射到一个相对较小的值域内. 传统的哈希存储 假设 ...

  6. 【转】CnBlogs自定义博客样式

    文章有一个好的排版,将能够增加阅读者对其内容的兴趣. 本文总结了如何美化博客园中文章的部分显示样式. 1.美化文章标题的显示样式 2.增添LaTex数学公式的显示 3.目录索引的显示 4.添加文章末尾 ...

  7. 【Git的基本操作四】永久删除文件后找回

    永久删除文件后找回 1. 已经添加到本地库的文件 使用 reset 命令回退到未删除的历史记录即可 2.添加到缓存区,没有提交到本地库的文件找回 git reset --hard HEAD 命令即可找 ...

  8. vue 编辑

    点击文字修改 <div class="baseInfo"> <p class="title">基本信息</p> <p ...

  9. beego中获取url以及参数的方式

    以下都全默认在controller下执行 获取当前请求的referer fmt.Println(this.Ctx.Request.Referer()) 输出:http://localhost:8080 ...

  10. OPNsense防火墙搭建实验环境,MSF与SSH进行流量转发

    OPNsense防火墙搭建实验环境,MSF与SSH进行流量转发 摘要: 记录实验过程中踩到的坑.介绍OPNsense防火墙的安装配置并搭建实验环境,利用msf的模块及ssh进行流量转发(LAN向DMZ ...