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. Python·——进程1

    1.进程背景知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序(的一个抽象). 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统 ...

  2. 2018-2019-2 《网络对抗技术》Exp0 Kali安装

    2018-2019-2 <网络对抗技术>Exp0 Kali安装 ---20165110 一.实验要求 1.下载 2.安装Kali 3.连接网络 4.共享文件 5.更新软件源 二.实验步骤 ...

  3. vim matchit 自定义配对关键字之间的跳转

    vim因其强大的扩展性一直深受linux程序员的喜爱,最近在用vim写verilog的时候,由于一个逻辑块中的begin end较多,常常会多写或者漏掉匹配关键字,很是苦恼,于是寻找匹配关键字间跳转的 ...

  4. Java I/O (1) - 输入/输出流

    先说概念: Java API中,可以从其中读入一个字节序列的对象叫做输入流,可以向其中写入一个字节序列的对象叫做输出流.这些字节序列的来源地 和 目的地 可以文件.网络连接甚至内存块.抽象类Input ...

  5. layabox typescript 安装固定版本

    安装最新版本方法: https://blog.csdn.net/adelais__/article/details/79181474 固定版本(比如2.1.5): C:\Users\Administr ...

  6. PEP8 规范

    Python PEP8 编码规范中文版   原文链接:http://legacy.python.org/dev/peps/pep-0008/ item detail PEP 8 Title Style ...

  7. java多线程管理 concurrent包用法详解

        我们都知道,在JDK1.5之前,Java中要进行业务并发时,通常需要有程序员独立完成代码实现,当然也有一些开源的框架提供了这些功能,但是这些依然没有JDK自带的功能使用起来方便.而当针对高质量 ...

  8. if(变量)的判断

    变量如果不为0,null,undefined,false,都会被处理为true.只要变量有非0的值或是某个对象,数组,字符串,都会认为true

  9. Linux 安装源码软件

    linux下,源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install) 过程中用到configure --prefix  --with:其中--pr ...

  10. 知识阅读的好处你都了解吗?芒果xo来告诉你答案

    阅读www.mangoxo.com让人才思敏捷,杜甫曾说:读书破万卷,下笔如有神:阅读让人心情愉悦,蒙台居曾说过:再没有比读书更廉价的娱乐,更持久的满足了:阅读让人思维灵活,狄德罗曾说过:不读书的人, ...