题目链接:

Balls and Boxes

Time Limit: 2000/1000 MS (Java/Others)    

Memory Limit: 65536/65536 K (Java/Others)

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
 
题意:
 
把n个球放到m个盒子里面,求上面这个式子的期望;
 
思路:
 
推期望公式的题,我推的过程跟题解的不太一样;
 
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
 
AC代码:
 
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <bits/stdc++.h>
  7. #include <stack>
  8. #include <map>
  9.  
  10. using namespace std;
  11.  
  12. #define For(i,j,n) for(int i=j;i<=n;i++)
  13. #define mst(ss,b) memset(ss,b,sizeof(ss));
  14.  
  15. typedef long long LL;
  16.  
  17. template<class T> void read(T&num) {
  18. char CH; bool F=false;
  19. for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
  20. for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
  21. F && (num=-num);
  22. }
  23. int stk[70], tp;
  24. template<class T> inline void print(T p) {
  25. if(!p) { puts("0"); return; }
  26. while(p) stk[++ tp] = p%10, p/=10;
  27. while(tp) putchar(stk[tp--] + '0');
  28. putchar('\n');
  29. }
  30.  
  31. const LL mod=1e9+7;
  32. const double PI=acos(-1.0);
  33. const LL inf=1e18;
  34. const int N=3e5+10;
  35. const int maxn=2e3+14;
  36. const double eps=1e-12;
  37.  
  38. LL gcd(LL a,LL b)
  39. {
  40. if(b==0)return a;
  41. return gcd(b,a%b);
  42. }
  43.  
  44. int main()
  45. {
  46. LL n,m;
  47. while(1)
  48. {
  49. read(n);read(m);
  50. if(n==0&&m==0)break;
  51. if(m==1)printf("0/1\n");
  52. else
  53. {
  54. LL temp=gcd(n*(m-1),m*m);
  55. printf("%lld/%lld\n",n*(m-1)/temp,m*m/temp);
  56. }
  57. }
  58.  
  59. return 0;
  60. }

  

hdu-5810 Balls and Boxes(概率期望)的更多相关文章

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

  2. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

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

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

  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. hdu 5810 Balls and Boxes 二项分布

    Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  7. HDU 5810 Balls and Boxes

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

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

  9. 2016 多校联赛7 Balls and Boxes(概率期望)

    Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. ...

随机推荐

  1. C指针的一些知识

    原文:http://blog.csdn.net/soonfly/article/details/51131141 前言:复杂类型说明 要了解指针,多多少少会出现一些比较复杂的类型,所以我先介绍一下如何 ...

  2. 设置网站URL启动

    当新建一个MVC WEB程序 当你打开一个视图按F5运行 这时候并且不能政策运行会出现与个错误 无法找到资源. 这时候站点的默认设置是 把这个个默认设置更改成 红色框框的地方为修改点 你以为这样就完了 ...

  3. django模型和字段

    一个模型(model)就是一个单独的.确定的数据的信息源,包含了数据的字段和操作方法.通常,每个模型映射为一张数据库中的表. 基本的原则如下: 每个模型在Django中的存在形式为一个Python类 ...

  4. angular组件层次与军事指挥层级职责的联系

    又继续读angular文档,发现自己之前理解还是有误.按官方文档的思路service不是属于component的,是属于module的.module才是负责完整领域逻辑的单位.demo的英雄编辑器给我 ...

  5. Hyper-v群集的仲裁模式配置依据

    1,仲裁配置的原理 节点多数(推荐用于含有奇数个节点的群集) 可以承受的故障节点数为节点数的一半(四舍五入)减去一.例如,七个节点的群集可以承受三个节点出现故障. 节点和磁盘多数(推荐用于含有偶数个节 ...

  6. Codeforces 918C - The Monster

    918C - The Monster 思路1: 右键在新窗口打开图片 代码: #include<bits/stdc++.h> using namespace std; #define ll ...

  7. springboot集成mybatis及mybatis generator工具使用

    原文链接 前言mybatis是一个半自动化的orm框架,所谓半自动化就是mybaitis只支持数据库查出的数据映射到pojo类上,而实体到数据库的映射需要自己编写sql语句实现,相较于hibernat ...

  8. Android 7.0真实上手体验

    Android 7.0真实上手体验 Android 7.0的首个开发者预览版发布了,支持的设备只有Nexus6.Nexus 5X.Nexus 6P.Nexus 9.Nexus Player.Pixel ...

  9. homestead 暴露接口到外网

    laravel 官方推荐的运行环境是homestead,但homestead是个虚拟机,你自己访问没问题,给别人联调怎么办? 一个大型项目肯定不止一个人开发,这个时候就需要将你虚拟机上的接口暴露给外网 ...

  10. bzoj2154: Crash的数字表格 莫比乌斯反演

    题意:求\(\sum_{i=1}^n \sum_{j=1}^m\frac{i*j}{gcd(i,j)}\) 题解:\(ans=\sum_{i=1}^n\sum_{j=1}^m \frac{i*j}{g ...