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 ...
随机推荐
- ThinkPHP开发api时多级控制器的访问方法
发开api时,经常会用到thinkphp的多级控制器,访问方法如下: 例如:有v1和v2两个版本的接口 v1:版本控制器(类文件位置为:application/api/controller/v1/Us ...
- 嵌套泛型参数IList<IList<Object>>如何传参
在调用第三方库的时候,有这么一个泛型参数,如下图: 按照经验,使用两个List嵌套声明变量即可: IList<IList<AnnotatedPoint2D>> outImag ...
- asp.net练习①——Application聊天室
已经好几年没写过代码,重新练习起代码,在这做做笔记备忘. aspx页面js代码: <script type="text/javascript"> function sh ...
- 使用iview ui库 [vue/no-parsing-error] Parsing error: x-invalid-end-tag报错
打开设置,搜索“vetur.validation.template”,设置完毕之后记得重启vscode 如果不行请使用下边方法 一. 问题日志 ✘ https://google.com/#q=vue% ...
- 并不对劲的2-SAT
说明 板板题链接 这个人讲得很清楚 WAWAWAWA 建的边"不完整",比如当限制是"x为1时y一定为1"时,连x->y的边时,忘记连y'->x'的 ...
- pat l2-14 列车调度 dilworth+nlog(n)最长上升子序列
关于dilworth定理 这里引用一个大神的(http://blog.csdn.net/xuzengqiang/article/details/7266034) 偏序的概念: 设A是一个非空集,P是A ...
- C#中word文档转html
var path = Request.Url.Host + ":" + Request.Url.Port + list[i].AnnexPath; //html保存路径 strin ...
- 在Global.asax中 注册Application_Error事件 捕获全局异常
参考于:https://shiyousan.com/post/635813858052755170 在ASP.NET MVC中,通过应用程序生命周期中的Application_Error事件可以捕获到 ...
- SQL:MYSQL入门
MYSQL(关系型数据库管理系统) 参考手册:http://www.w3school.com.cn/sql/index.asp 给大家讲一下数据库:常见的有 ACCESS.MSSSQL.MYSQL.O ...
- Go 工作空间 深度解析
介绍 这篇文档举例证明了一个简单地 Go package 并且介绍了 go tool,标准的方法来 fetch, build,and install Go package and commands. ...