[luoguP1227] [JSOI2008]完美的对称(sort)

传送门

排序!

#include <cstdio>
#include <iostream>
#include <algorithm>
#define N 20001

int n;

struct node
{
	double x, y;
}a[N], b[N];

inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

inline bool cmp1(node x, node y)
{
	return x.x < y.x || (x.x == y.x && x.y < y.y);
}

inline bool cmp2(node x, node y)
{
	return x.x > y.x || (x.x == y.x && x.y > y.y);
}

int main()
{
	int i;
	double x, y;
	n = read();
	for(i = 1; i <= n; i++)
	{
		a[i].x = b[i].x = read();
		a[i].y = b[i].y = read();
	}
	std::sort(a + 1, a + n + 1, cmp1);
	std::sort(b + 1, b + n + 1, cmp2);
	x = a[1].x + b[1].x;
	y = a[1].y + b[1].y;
	for(i = 2; i <= n; i++)
		if(a[i].x + b[i].x != x || a[i].y + b[i].y != y)
		{
			puts("This is a dangerous situation!");
			return 0;
		}
	x /= 2.0;
	y /= 2.0;
	printf("V.I.P. should stay at (%.1lf,%.1lf).
", x, y);
	return 0;
}

  

原文地址:https://www.cnblogs.com/zhenghaotian/p/7498342.html