HDU 3569 Imaginary Date 简单期望

推一下公式,就会发现是这个。。

因为设结果有x种方案。则每个数字出现的概率都均等,然后和就是x*m

每种方案的概率是1/x

每个数出现的概率都是1/n

所以每个方案的和就是 sum/n *m

#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1005;
int main() {
	int n, m, K, cas, T = 0, x;
	scanf("%d", &cas);
	while (cas-->0) {
		double sum = 0;
		scanf("%d%d%d", &n, &m, &K);
		for (int i = 0; i < n; ++i) {
			scanf("%d", &x);
			sum += x;
		}
		printf("Case %d: %.5f\n", ++T, sum * m / n);
	}
	return 0;
}
时间: 2024-08-26 10:33:04

HDU 3569 Imaginary Date 简单期望的相关文章

hdu 3853 概率DP 简单

http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意:有R*C个格子,一个家伙要从(0,0)走到(R-1,C-1) 每次只有三次方向,分别是不动,向下,向右,告诉你这三个方向的概率,以及每走一步需要耗费两个能量,问你走到终点所需要耗费能量的数学期望: 回头再推次,思想跟以前的做过的类似 注意点:分母为0的处理 #include <cstdio> #include <cstring> #include <algorithm>

hdu 1312 DFS算法简单题

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 此题与油田那题很像是练习深搜的好题,题意是从"@"开始,遍历整个图,找到连接的 "."有多少个 但要考虑变化,简单处理下就行了,主要是斜角的不要了,而且判断结束方式也不一样 具体看代码吧 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

HDU 1018 Big Number (简单数学)

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25649    Accepted Submission(s): 11635 Problem Description In many applications very large integers numbers are required. Some of these

HDU 3232 &amp;amp;&amp;amp; UVA 12230 (简单期望)

Crossing Rivers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 738    Accepted Submission(s): 387 Problem Description You live in a village but work in another village. You decided to follow t

HDU 4336:Card Collector 期望+状压

Card Collector 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 去商店里买零食,每包零食里最多有1张卡片,也有可能没有,问要集齐所有n(n≤20)种卡片所需要购买零食个数的期望. 题解: 设dp[i](二进制,对应位为1表示已经有该卡片)为以当前状态为起点还需要购买零食个数的期望,则dp[0]即答案 对DP求解期望有问题的可以看下这里 代码 #include<stdio.h>#include<string.h

HDU 1711 Number Sequence (简单KMP)

#include <stdio.h> #include <string.h> int next[10005]; int str1[1000005],str2[10005]; void build_next(int len2) { int i=0,j=-1; next[0] = -1; while (i < len2) { if (j==-1 || str2[i] == str2[j]) { i++; j++; if (str2[i] != str2[j]) { next[i]

HDU - 1005 Number Sequence(简单矩阵快速幂)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 题意:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 就是这道题目,然而找了一晚上的错误 \("▔□▔)/\("▔□▔)/\("▔□▔)/. 1 #include <iostream> 2 #include <cstring> 3 using namespace std;

HDU 2084 数塔(简单DP入门)

数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 41852    Accepted Submission(s): 24820 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?

hdu 1003 Max Sum 简单DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 转移方程:dp[i]=max(dp[i-1]+a[i],a[i]) 虽然是dp 但不用真的申请一个dp数组 #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <cmath> #include <cstring> #in