随机类问题解法——利用统计学:1229B

本文搬运自本人高中时期CSDN博客,若图片加载不出来,可到原文查看:https://blog.csdn.net/zhangtingxiqwq/article/details/135332294

http://47.92.197.167:5283/contest/440/problem/2

结论:

nn 个随机 [0,1][0,1] 变量的期望最小值为 1n+1\frac 1 {n+1}

因此我们以输入的数为随机种子生成随机数。相同的种子生成的数是一样的,所以相当于有 mm (不同数)个数的随机数。我们取最小值即可。

32bits的空间可以切成8份,提高正确性

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
#ifdef ONLINE_JUDGE
#include "count.h"
#endif
#include <random>
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long u64;
void init(void *mem) {
/* Your Code Here */
memset(mem, 0xff, 32);
}
void add(void *mem, int i, int w) {
((unsigned*)mem)[i] = min(((unsigned*)mem)[i], (unsigned)w);
}
void insert(u64 data, void *mem) {
/* Your Code Here */
mt19937_64 rng(data);
for(int i=0; i<8; ++i) add(mem, i, rng() & 0xffffffff);
}
u64 count(void *mem) {
/* Your Code Here*/
double ans = 0, c = (double)(0xffffffff);
for(int i = 0; i < 8; ++i) ans += ((unsigned*)mem)[i];
return round(c/(ans/8))-1;
}