hdu 5810 Balls and Boxes 二项分布
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
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.
The input is terminated by n = m = 0.
2 2
0 0
1/2
In the second sample, there are four possible outcomes, two outcomes with V = 0 and two outcomes with V = 1.
#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 二项分布的更多相关文章
- HDU 5810 Balls and Boxes(盒子与球)
Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- HDU 5810 Balls and Boxes (找规律)
Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- HDU 5810 Balls and Boxes 数学
Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- HDU 5810 Balls and Boxes
n*(m-1)/(m*m) #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio&g ...
- HDU 5810 Balls and Boxes ——(数学,概率,方差)
官方题解看不太懂,参考了一些人的博客以后自己证明如下: 其中D(X)和E(X)的公式如下(参考自百度百科): 其中 p = 1 / m .(这是每一个单独事件发生的概率期望,在这里单独事件指的是一个球 ...
- 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 ...
- 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/O ...
- 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 ...
随机推荐
- Qt 4.5发布(最大的变动是换用LGPL许可证,移植进了苹果的Cocoa框架。之前的Qt只支持Carbon框架,现在的Qt 4.5两者都支持。单一源代码创建出支持32位或64位字节的Intel或PowerPC Mac二进制文件)
Nokia的开源Qt开发工具正式发布了4.5版.如前所述,Qt 4.5最大的变动是换用LGPL许可证,目前采用的三个许可证分别为LGPL/GPL和商业许可证. 新版 ...
- 怎样使用构造函数: Vue()?
1. 新建一个 .html 文件 => 引入一个在线的 vue 库 => 写一个带 id 的 html 标签 => 写一个 script 标签, 这里的 vApp 是 Vue() 这 ...
- C#解决界面闪烁
添加缓冲: private void SetDoubleBuffer() { base.SetStyle( ControlStyles.OptimizedDoubleBuffer | ControlS ...
- GNU g++常用编译选项用法
GNU g++常用编译选项用法 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/30686/showart_1210761.html GCC ...
- 【其他】BootCDN
BootCDN 稳定.快速.免费的前端开源项目 CDN 加速服务 是 Bootstrap 中文网支持并维护的前端开源项目免费 CDN 服务,致力于为 Bootstrap.jQuery.Angular. ...
- MySQL之常用查询
1) 查询字符集 show variables like 'character%'; 2)查看版本 select version(); 3) 共享表空间的数据文件存储路径 show variables ...
- element-ui中点击菜单,改变当前菜单背景颜色
需求: vue项目中,点击左侧菜单,tags页显示当前打开的菜单,并且高亮显示当前菜单 实现效果: 实现代码:在vuex里面定义tags存放所有打开的菜单,和当前打开的索引curtagsIndex:, ...
- RPC性能优化
优化 1:元数据共享 hessian 序列化会将两种信息写到输出流: 元数据:即类全名,字段名 值数据:即各个字段对应值(如果字段是复杂类型,则会递归传递该复杂类型 的元数据和内部字段的值数据) 在 ...
- 分布式之协调服务Zookeeper专题第一讲
写在前面: 再谈架构演进: 1.单体架构->tomcat(war) 演进:水平拆分(服务拆分,(用户服务,订单服务,商品服务)) 涉及问题:1).服务通信(webservice) 2).三态问题 ...
- Manjaro18+kde 更换壁纸重启失效
更换壁纸 在kde的桌面右键->配置桌面 壁纸里更换壁纸,我不能直接添加图像并应用.我的系统在这样操作后重启就会发现一切都被重置了.刚刚添加的图片也不见了. 于是,我就模范原本存在壁纸文 ...