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

题目大意:区分作业

思路解析:

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

废话不多说,代码如下:

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using T = pair<int, int>;
//set<int>S;
//unordered_map<int, int>mp;
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;
}

求得期望是这样的:

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using T = pair<int, int>;
//set<int>S;
//unordered_map<int, int>mp;
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;
}

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值