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

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <map>
  8. #include <cmath>
  9. #include <set>
  10. #include <stack>
  11. #include <queue>
  12. #include <vector>
  13. #include <bitset>
  14. #include <functional>
  15.  
  16. using namespace std;
  17.  
  18. #define LL long long
  19. const int INF = 0x3f3f3f3f;
  20.  
  21. LL n,m;
  22.  
  23. LL gcd(LL x,LL y)
  24. {
  25. return x?gcd(y%x,x):y;
  26. }
  27.  
  28. int main()
  29. {
  30. while(~scanf("%lld%lld",&n,&m)&&(n+m))
  31. {
  32. if(m==1) {printf("0/1\n");continue;}
  33. n=(m-1)*n;
  34. m=m*m;
  35. printf("%lld/%lld\n",n/gcd(n,m),m/gcd(n,m));
  36. }
  37. return 0;
  38. }

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. Tomcat 配置MySQL连接池

    <!--配置mysql数据库的连接池,         需要做的额外步骤是将mysql的Java驱动类放到tomcat的lib目录下                maxIdle 连接池中最多可 ...

  2. Trie树详解(转)

    特别声明 本文只是一篇笔记类的文章,所以不存在什么抄袭之类的. 以下为我研究时参考过的链接(有很多,这里我只列出我记得的): Trie(字典树)的应用——查找联系人 trie树 Trie树:应用于统计 ...

  3. FineCMS v5.4.1 后台getshell

    0x01.前言 最近在学代码审计,拿finecms学习的时候偶然发现的,应该算个1day吧 0x02.正文 FineCMS v5.4.1 后台域名配置处 域名配置文件config/domain.php ...

  4. k8s环境清理

    每一种方法 #!/bin/shdocker rm -f $(docker ps -qa)docker volume rm $(docker volume ls -q)cleanupdirs=" ...

  5. Android 菊花加载工具类

    先看看实现效果图 1.首先自定义一个类继承系统ProgressDialog /** * Created by hanbao0928 on 2018/11/1. */ public class Dial ...

  6. CentOS 7 lnmp环境配置laravel项目的问题总结!

    一.最常见的几个问题 1.部署好站点后,访问站点的时候始终是“File Not Found”!(nginx中的路由配置问题) 2.除了根目录可以访问其它的访问全是403问题!(权限问题) 3.除了根目 ...

  7. grid布局

    display: grid; //行 //每一行中有几块,每块所占的width的百分比(1) grid-template-columns: 70% 30%; //每个div的width 100px,自 ...

  8. Eclipse oxygen 版本汉化教程

    Eclipse oxygen 版本汉化步骤如下: 第一步:打开Eclipse 第二步:浏览器打开网址 http://www.eclipse.org/babel/downloads.php 1.复制对应 ...

  9. python requests库爬取网页小实例:ip地址查询

    ip地址查询的全代码: 智力使用ip183网站进行ip地址归属地的查询,我们在查询的过程是通过构造url进行查询的,将要查询的ip地址以参数的形式添加在ip183url后面即可. #ip地址查询的全代 ...

  10. Linux 学习笔记 2:文件系统

    1.文件系统层次结构 系统目录内容: /: 根目录(之后的/都是目录分隔符) /home:用户目录 /bin: Unix常用命令,如bash, date, cat, tar等 /sbin: 管理员命令 ...