UVA 10585 - Center of symmetry

/*
*	problem: UVA 10585 - Center of symmetry
*	url: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1526
*	strtege: 离散化 x从小到大排序,x相同y从小到大排序,一次算对称点是否相等。注意奇数个点和偶数个点
*	Author: johnsondu
*	time: 2013-4-25
*/

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std ;

#define M 10005
#define min(x, y) (x > y ? y : x)
#define max(x, y) (x > y ? x : y)
int n, X, Y ;
bool flag ;
struct Node
{
	int x, y ;
}node[M] ;
 

void solve ()
{
	double X = (node[0].x + node[n-1].x) / 2.0 ;
	double Y = (node[0].y + node[n-1].y) / 2.0 ;
	for (int i = 1; i < n/2; i ++)
		if ((node[i].x+node[n-i-1].x)/2.0 != X ||
			(node[i].y+node[n-i-1].y)/2.0 != Y)
			flag = true ;

	if (n & 1)
		if (node[n/2].x*1.0 != X || node[n/2].y*1.0 != Y)
			flag = true ;
}

bool cmp (const Node &a, const Node &b)
{
	if (a.x != b.x)
		return a.x < b.x ;
	return a.y < b.y ;
}

int main()
{
	int tcase ;
	scanf ("%d", &tcase) ;
	while (tcase --)
	{
		scanf ("%d", &n) ;
		X = Y = 0 ;
		for (int i = 0; i < n; i ++)
			scanf ("%d%d", &node[i].x, &node[i].y) ;
		
		flag = false ;
		sort (node, node + n, cmp) ;
		solve () ;
		if (!flag)
			printf ("yes\n") ;
		else printf ("no\n") ;
	}
	return 0 ;
}

你可能感兴趣的:(UVA 10585 - Center of symmetry)