【HDU 5810多校】Balls and Boxes(打表/数学)

1.打表找规律,下面是打表程序:

#include <iostream>
#include <cstdio>
#define ll long long
#define N 100005
using namespace std;
ll n,m,b[N],ans,num;
ll sqr(ll x)
{
	return x*x;
}
void dfs(ll r){
	if(r==0){
		num++;
		for(int i=1;i<=m;i++)
			ans+=sqr(b[i]);
		return;
	}
	for(int i=1;i<=m;i++)
	{
		b[i]++;
		dfs(r-1);
		b[i]--;
	}
}
int main() {
	while(~scanf("%lld%lld",&n,&m)){
		for(ll r=1;r<=n;r++){
			ans=num=0;
			dfs(r);
			ans=m*ans-r*r*num;
			num=m*m*num;
			ll g=__gcd(ans,num);
			printf("r=%lld: %lld/%lld\n",r,ans/g,num/g);
		}
	}
}

2.数学

V其实就是二项式分布的方差,可以这么理解:

样本是第i个盒子:每次把1个球扔进第i个盒子的概率都是1/m,扔不进就是1-1/m,扔了n个球,于是Xi服从二项式分布。

那么就可以直接用二项式的方差公式$D(X)=n\cdot p\cdot (1-p)$ 这里的p就是1/m。下面是AC程序:

#include <algorithm>
#include <cstdio>
#define ll long long
using namespace std;
ll n,m;
int main() {
	while(scanf("%lld%lld",&n,&m),n){
		ll a=n*(m-1),b=m*m;
		ll g=__gcd(a,b);
			printf("%lld/%lld\n",a/g,b/g);
	}
}

  

时间: 2024-07-31 08:27:30

【HDU 5810多校】Balls and Boxes(打表/数学)的相关文章

HDU 5810 Balls and Boxes(盒子与球)

HDU 5810 Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment

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 Problem Description Mr. Chopsticks is interested in random phenomena, and he conducts an experi

hdu 4893 (多校1007)Wow! Such Sequence!(线段树&amp;二分&amp;思维)

Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 352    Accepted Submission(s): 104 Problem Description Recently, Doge got a funny birthday present from his new friend, Prot

hdu-5810 Balls and Boxes(概率期望)

题目链接: 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

hdu 5344 (多校联赛) MZL&#39;s xor --- 位运算

here:    首先看一下题吧:题意就是让你把一个序列里所有的(Ai+Aj) 的异或求出来.(1<=i,j<=n) Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1≤i,j≤n) The xor of an array B is defined as B1 xor B2...xor B

HDU 4915 多校5 Parenthese sequence

比赛的时候想了一个自认为对的方法,WA到死,然后还一直敲下去,一直到晚上才想到反例 找是否存在解比较好找,这种左右括号序列,把(当成1,把)当成-1,然后从前往后扫,+1或者-1 遇到?就当初(,然后如果扫到最后 中间没有出现负数说明左括号没问题 然后同样的方法从后往前扫,判断右括号那里是不是有问题即可.都没问题就有解,否则无解 当然应该要先判断下序列长度是不是偶数,奇数肯定是无解 至于为什么要像之前的处理即可判断有无解,首先只有正好走完的时候 和值为0才是真正合法(因为这个时候左右括号都对应了

HDU 4866 多校1 主席树+扫描线

终于是解决了这个题目了 不过不知道下一次碰到主席树到底做不做的出来,这个东西稍微难一点就不一定能做得出 离散化+扫描线式的建树,所以对于某个坐标二分找到对应的那颗主席树,即搜索出结果即可(因为是扫描线式的建树,找到对应的树之后,就知道该点上面的线段有多少条了) 其他就是普通主席树的操作了 主席树里面维护两个东西,一个就是普通的那种在该区间的节点数目,另外就是权值 #include <iostream> #include <cstdio> #include <cstring&g

博客园首页新随笔联系管理订阅 随笔- 524 文章- 0 评论- 20 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): 798    Accepted Submission(s): 527 Problem Description Mr. Chopsticks is interested in random phenomena, and he conducts an experi

hdu 3641 数论 二分求符合条件的最小值数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*==================================================== 二分查找符合条件的最小值 ======================================================*/ ll solve() { __int64 low = 0, high = INF, mid ; while(low <=