这道题并不顺利。。排序出了问题。。其实自己测样例的时候发现了。。但是今天没敲,,晚上重新写。。不过收获很大,,我没看题就想了方法,我目前知道的,,排序,,集合,,map
#include<cstdio>
#include<iostream>
#include<string.h>
using namespace std;
const int maxn = 1000 + 5;
struct node
{
int x,y;
}a[maxn],b[maxn],temp;
int main()
{
int N,n,mark = 0;
cin >> N;
for(int count = 1; count <= N; ++count)
{
mark = 0;
cin >> n;
for(int i = 0; i < n; ++i)cin >> a[i].x >> a[i].y;
for(int i = 0; i < n - 1; ++i)
{
for(int j = i + 1; j < n; ++j)
{
if(a[i].x > a[j].x)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
else if(a[i].x==a[j].x&&a[i].y > a[j].y)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(int i = 0; i < n; ++i)b[i] = a[n-i-1];
for(int i = 0; i < n - 1; ++i)
{
for(int j = i + 1; j < n; ++j)
{
if(b[i].x==b[j].x&&b[i].y > b[j].y)
{
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
int x = a[0].x + b[0].x;
for(int i = 0; i < n; ++i)
{
if(a[i].y==b[i].y&&a[i].x+b[i].x==x)continue;
else if(a[i].y!=b[i].y&&2*a[i].x==x&&2*b[i].x==x)continue;
else {mark = 1;break;}
}
if(mark==1)cout <<"NO"<< endl;
else cout <<"YES"<<endl;
}
return 0;
}