HDU 5810 Balls and Boxes ——(数学,概率,方差)
官方题解看不太懂,参考了一些人的博客以后自己证明如下:

其中D(X)和E(X)的公式如下(参考自百度百科):

其中 p = 1 / m 。(这是每一个单独事件发生的概率期望,在这里单独事件指的是一个球放到m个盒子里面,放到每个盒子里面的概率都是一样的,所以期望都是1 / m了)
推出了公式以后,代码就很好写了。代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long ll; int main()
{
int n,m;
while(scanf("%d%d",&n,&m)==)
{
if(n== && m==) break;
ll a = 1LL * n * m - n;
ll b = 1LL * m * m;
if(a==)
{
printf("0/1\n");
continue;
}
ll g = __gcd(a,b);
printf("%I64d/%I64d\n",a/g,b/g);
}
}
此外,还想提的一点是,网上很多博客包括仓鼠学长都是用猜想的方式推出公式的,其实猜想也是有技巧的,猜想也是包含了运气和经验成分在里面的。过程如下:





看来以后这方面的能力也要提高啊=。=
HDU 5810 Balls and Boxes ——(数学,概率,方差)的更多相关文章
- 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(盒子与球) 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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5810 Balls and Boxes
n*(m-1)/(m*m) #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio&g ...
- 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 ...
- 2016 多校联赛7 Balls and Boxes(概率期望)
Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. ...
- HDU_5810_数学,概率,方差
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5810 大意:将n个球往m个盒子中投,每个球被投入每个盒子的概率相等,求方差. 看题解说,这是二项分布( ...
- HDU 4611 Balls Rearrangement (数学-思维逻辑题)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4611 题意:给你一个N.A.B,要你求 AC代码: #include <iostream> ...
随机推荐
- LeetCode:176.第二高的薪水
题目链接:https://leetcode-cn.com/problems/second-highest-salary/ 题目 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Sal ...
- vue进阶:vue-router之导航守卫、路由元信息、路由懒加载
1.导航被触发 2.在失活的组件里调用离开守卫:beforeRouteLeave —— 组件内守卫(离开组件). 3.调用全局的beforeEach守卫 —— 全局守卫(进入组件). 4.在重用组件里 ...
- C# 斐波那契数列 第n项数字/前n项的和
static void Main(string[] args) { int a = Convert.ToInt32(Console.ReadLine()); //求第n位数字是多少 Console.W ...
- OSCP-Kioptrix2014-2 漏洞利用
pChart 2.1.3 文件包含漏洞 搜索漏洞 查看漏洞理由代码: hxxp://localhost/examples/index.php?Action=View&Script=%2f..% ...
- Hadoop2.7.3集群安装scala-2.12.8 和spark2.7
Apache Spark™是用于大规模数据处理的统一分析引擎. 从右侧最后一条新闻看,Spark也用于AI人工智能 spark是一个实现快速通用的集群计算平台.它是由加州大学伯克利分校AMP实验室 开 ...
- mysql sleep 死锁例子
表结构 CREATE TABLE `orders` ( `order_id` int(11) NOT NULL, `order_addr` varchar(255) DEFAULT NULL ) EN ...
- Windows环境中编译opencv3.0同时加入OPENCV_contrib库及解决遇到相关问题[contrib 必须要3.1以上的opencv才支持了]
更新:现在contrib库必须要opencv3.1以上才能支持编译通过了. 方法和步骤还是和本篇文章一样. ############################################## ...
- MySQL添加唯一索引
1 语法如下 ALTER TABLE `t_user` ADD unique(`username`);
- 09-【el表达式和jstl标签库】
el表达式和jstl标签库 一:el表达式:表达式语言,jsp页面获取数据比较简单1.el表达式的语法(掌握)el表达式通常取值是获取作用域对象中的属性值:${属性名}=>是el表达式的简写的形 ...
- swiper 使用心得
首先,我在这次学习的最大收益是,学习新框架.或者技术,先找官方文档比较好,那里的很全,你想要的基本都有的,如果没有那就是不支持喽. 然后简单概括下是怎么用的(比较谦虚,大家勿怪) 一 .找他的官方文档 ...