比赛 20161223 评测结果 AAAAAAAAAA
题目名称 哞投 最终得分 100
用户昵称 confoo 运行时间 0.271 s
代码语言 C++ 内存使用 0.27 MiB
提交时间 2016-12-23 19:47:56
显示代码纯文本
//sro FarmerJohn orz
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#define file(x) "moocast." #x
const int V = 1010;
using std::max;
struct P{int x, y;}p[V];
inline int sq(int x) {return x*x;}
bool rc(const P& a, const P& b, int x) {return sq(a.x - b.x) + sq(a.y - b.y) <= x;}
int n, mid, fa[V];
int find(int x) {return x == fa[x] ? x : fa[x] = find(fa[x]);}
inline bool check() {
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int i = 1; i <= n; i++) for (int j = 1; j < i; j++) if(rc(p[i], p[j], mid)) fa[find(i)] = find(j);
	int c = 0;
	for (int i = 1; i <= n; i++) c += i == fa[i];
	return c == 1;
}
int main() {
	freopen(file(in), "r", stdin);
	freopen(file(out), "w", stdout);
	scanf("%d", &n);
	int l = 0, r = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &p[i].x, &p[i].y);
		for (int j = 1; j < i; j++) r = max(r, sq(p[i].x - p[j].x) + sq(p[i].y - p[j].y));
	}
	++r;
	while (l < r) {
		mid = l + r >> 1;
		if (check()) r = mid;
		else l = mid + 1;
	}
	printf("%d", l);
}