洛谷 P1227 完美的对称 题解-编程题目及题解论坛-编程-擎雷博客

洛谷 P1227 完美的对称 题解

原题链接(洛谷):https://www.luogu.com.cn/problem/P1227

题解(C++):

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 2e4 + 5;
int n;
struct Point {
	double x, y;
} p[N], m;

bool cmp(const Point &a, const Point &b) {
	if (a.x != b.x)return a.x < b.x;
	else return a.y < b.y;
}
signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i].x >> p[i].y;
	}
	sort(p + 1, p + n + 1, cmp);
	m.x = (p[1].x + p[n].x) / 2;
	m.y = (p[1].y + p[n].y) / 2;
	for (int i = 2, j = n - 1; i <= j; i++, j--) {
		if ((p[i].x + p[j].x) / 2 != m.x ||
		        (p[i].y + p[j].y) / 2 != m.y) {
			cout << "This is a dangerous situation!" << endl;
			return 0;
		}
	}
	cout << fixed << setprecision(1);
	cout << "V.I.P. should stay at (" << m.x << "," << m.y << ").\n";
}
请登录后发表评论

    没有回复内容