题目描述:给出平面上N(N<=1000)个点。问是否可以找到一条竖线,使得所有点左右对称,如图所示:
则左边的图形有对称轴,右边没有。
找出中间轴,枚举验证是否有对称点即可
#include <iostream>
#include <set>
#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
struct Node{
int x,y;
}c[1005];
int temp;
bool comp(struct Node a,struct Node b){
if(a.x!=b.x)
return a.x<b.x;
else{
if(a.x*2>temp)
return a.y<b.y;
else
return a.y>b.y;
}
}
bool solve(int k){
if(k%2==0){
int mid=c[k/2].x*2;
for(int i=0;i<k/2;i++){
if((c[i].x+c[k-i].x)!=mid)
return 0;
else{
if(c[i].x!=c[k-i].x&&c[i].y!=c[k-i].y)
return 0;
}
}
return 1;
}else{
int mid=c[k/2].x+c[k/2+1].x;
for(int i=0;i<=k/2;i++)
if((c[i].x+c[k-i].x)!=mid)
return 0;
else{
if(c[i].x!=c[k-i].x&&c[i].y!=c[k-i].y)
return 0;
}
return 1;
}
}
int main()
{
int t,n;
while(cin>>t){
while(t--){
int minn=999999;
int maxn=-999999;
memset(c,0,sizeof(c));
cin>>n;
int k=-1;
while(n--){
k++;
cin>>c[k].x>>c[k].y;
minn=min(c[k].x,minn);
maxn=max(c[k].x,maxn);
}
temp=minn+maxn;
sort(c,c+k+1,comp);
bool ans=solve(k);
if(ans) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
}