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 ...
随机推荐
- python基础(十二)--模块
模块的导入方式 import os 调用时os.rename from os import rename #只导入的特定功能 调用时rename() from asynico.events impo ...
- jwt认证规则
目录 认证规则图 django不分离 drf分类 认证规则演变图 数据库session认证:低效 缓存认证:高效 jwt认证:高效 缓存认证:不易并发 jwt认证:易并发 JWT认证规则 优点 格式 ...
- flask 接收参数小坑
前后端分离: 1.get方式: items = dict(request.args.items()) app_name = items["app_name"].strip() 或 ...
- Codeforces 1238G. Adilbek and the Watering System
传送门 最关键的想法就是每个位置一定用的是当前能用的最便宜的水,因为到后面可能有更便宜的 然后其他还没用上的水我们也留着,假装此时已经买了,但是如果发现后面有更优的再反悔也不迟 每相邻两个朋友之间我们 ...
- PyQt5创建多线程
参阅: https://blog.csdn.net/chengmo123/article/details/96477103 https://www.cnblogs.com/zhuminghui/p/9 ...
- centos7上搭建NFS的实践
NFS 即network file system 可用于向k8s集群提供持久存储 最小化安装centos后 把网卡设置好了后 1.关闭防火墙 [root@NFS ~]# systemctl stop ...
- WPF 键盘事件
private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.KeyStates==Keyboard.GetKeyStates( ...
- QByteArray详解
QByteArray在串口通讯中经常被使用,有一定必要较为全面详细的对QByteArray进行阐述.本文通过以下几个部分加以介绍: 1. 初始化 2. 访问与赋值 3. 添加.删除.插入与替换操作 4 ...
- windows服务总结
一.创建windows服务项目创建完成后结构,如: 其中,Program.cs代码: using System; using System.Collections.Generic; using Sys ...
- Lab 色彩模型和取值范围
L∈(0,100) a∈(-128,127) b∈(-128,127) opencv 的Lab数据对齐做了量化,使其处于0-255范围 L=L*2.55 a=a+128 b=b+128