HDU 3569 Imaginary Date 简单期望

时间:2023-03-08 22:48:36

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

由于设结果有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;
}