I.It‘s bertrand paradox. Again!(2024牛客寒假训练营)

I.It‘s bertrand paradox. Again!(2024牛客寒假训练营)_第1张图片

题目大意:区分作业

思路解析:

题目本质是将两份作业区分开来,所以我们想办法找一个特征值即可,举一个简单的例子:假设我们拿生成的半径的期望作为特征值,假设我们选取的特征值为20,那么对于小于20的特征值就是一名同学的作业,大于20的另外一个特征值就是另外一名同学的作业,那么问题来了,特征值如何找呢?其实我们可以在本地编译器上跑代码,随机生成一些符合条件的数值然后求期望即可。

废话不多说,代码如下:

#include
using namespace std;
using ll = long long;
using T = pair;
//setS;
//unordered_mapmp;
const int N = 1e5;
int a[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	double A{}, B{};
	std::random_device rd;  // 随机数引擎的种子源
	std::mt19937 gen(rd()); // 以 rd() 播种的 mersenne_twister_engine
	std::uniform_int_distribution<> distrib(-99, 99);
	std::uniform_int_distribution<> R(1, 100);
	// 用 distrib 变换 gen 所生成的随机 unsigned int 为 [-99, 99] 中的 int
	for (int n = 1; n <= N; ++n) {
		int x = distrib(gen);
		int y = distrib(gen);
		int r = R(gen);
		while (!(x + r <= 100 && x - r >= -100 && y + r <= 100 && y - r >= -100)) {
			r = R(gen);
		}
		A += r;
	}
	for (int n = 1; n <=N; ++n) {
		int x = distrib(gen);
		int y = distrib(gen);
		int r = R(gen);
		while (!(x + r <= 100 && x - r >= -100 && y + r <= 100 && y - r >= -100)) {
			x = distrib(gen);
			y = distrib(gen);
			r = R(gen);
		}
		B += r;
	}
	cout << A/N << " " << B/N;
	return 0;
}

求得期望是这样的:

I.It‘s bertrand paradox. Again!(2024牛客寒假训练营)_第2张图片

#include
using namespace std;
using ll = long long;
using T = pair;
//setS;
//unordered_mapmp;
const int N = 2e5 + 10;
int a[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t; cin >> t;
	int n = t;
	int sum{};
	while (t--) {
		int x, y, r; cin >> x >> y >> r;
		sum += r;
	}
	if (sum / n < 21)cout << "bit-noob";
	else cout << "buaa-noob";
	return 0;
}

你可能感兴趣的:(算法)