比赛 EYOI与SBOI开学欢乐赛7th 评测结果 AAAAWEEWEA
题目名称 聪明的猴子 最终得分 50
用户昵称 湖岸与夜与咸鱼 运行时间 0.675 s
代码语言 C++ 内存使用 5.13 MiB
提交时间 2022-09-23 20:45:59
显示代码纯文本
// 河南省实验中学 高中 21级 关天泽

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define re register

const int INF = 0x3f3f3f3f;
using namespace std;

int m, n, monkey[1050]; 
pair<int, int> tree[550];
double far[550][550];
int l, r;	
int walk[550][1050];
int tot[1050];
bool can[550];

bool cmp(int a, int b){
	return a > b;
}

int slove(int x){
//	cout << endl << endl << endl << x << endl;

	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= 2 * n; j++) walk[i][j] = 0;
		tot[i] = 0;
		can[i] = 0;
	}
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++){
//			cout << i << " " << j << " " << far[i][j] << " " << monkey[x] << endl;
			if (far[i][j] <= monkey[x]){
				tot[i]++, tot[j]++;
				walk[i][tot[i]] = j;
				walk[j][tot[j]] = i;
//				cout << 1 << endl;
			}
//			for (int i = 1; i <= n; i++){
//				for (int j = 1; j <= tot[i]; j++) cout << walk[i][j] << " ";
//				cout << endl;
//			}
		}
	
	queue<int> q;
	q.push(1);
	can[1] = 1;
	while(q.size()){
		int y = q.front();
		q.pop();
		for (int i = 1; i <= tot[y]; i++)
			if (can[walk[y][i]] == 0){
				can[walk[y][i]] = 1;
				q.push(walk[y][i]);
			}
	}
	for (int i = 1; i <= n; i++){
//		cout << can[i] << " ";
//		cout << i << " " << x << endl;
		if (can[i] == 0) return 0;
	}
	return 1; 
}

int main(){
	freopen("monkey.in", "r", stdin);
	freopen("monkey.out", "w", stdout);
	cin >> m;
	for (int i = 1; i <= m; i++) cin >> monkey[i];
	sort (monkey + 1, monkey + 1 + m, cmp);
//	for (int i = 1; i <= m; i++) cout << monkey[i] << " ";
//	cout << endl;
	l = 1, r = m;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> tree[i].first >> tree[i].second;
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++){
			int x = tree[i].first - tree[j].first;
			int y = tree[i].second - tree[j].second;
			far[i][j] = sqrt(x * x + y * y);
			far[j][i] = far[i][j];
		}
//	for (int i = 1; i <= n; i++){
//		for (int j = 1; j <= n; j++){
//			cout << far[i][j] << " ";
//		}
//		cout << endl;
//	}
	while(l < r){
		int mid = (l + r) / 2;
		int x = slove(mid);
//		cout << mid << " " << x << endl;
		if (x == 1) l = mid + 1;
		if (x == 0) r = mid;
	}
	cout << l - 1 << endl;
	return 0;
}