看到这个题这么水,写完马上交,结果WA了7发=_=
还是要仔细地考虑一个问题呀
注意对称轴上有多个点的情况,除此之外,从对称轴往两边比就好了
用了两次sort,第一次给整个点排序,第二次给右半边的点排序,保证右半边的横坐标相同的点是按照纵坐标降序排列的
#include <iostream>
#include <algorithm>
using namespace std;
using pa=pair<int,int>;
int t,n;
pair<int,int> arr[1010];
bool judge();
int main(){
ios_base::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;++i)
cin>>arr[i].first>>arr[i].second;
sort(arr+1,arr+n+1);
sort(arr+(n>>1)+1+(n&1),arr+n+1,[](const pa& a,const pa& b){return a.first<b.first||a.first==b.first&&a.second>b.second;});
cout<<(judge()?"YES\n":"NO\n");
}
return 0;
}
bool judge(){
int le,ri,k;
if(n&1)
le=n>>1,ri=le+2,k=arr[(n>>1)+1].first<<1;
else
le=n>>1,ri=le+1,k=arr[le].first+arr[ri].first;
while((arr[le].first<<1)==k&&le>=1)--le;
while((arr[ri].first<<1)==k&&ri<=n)++ri;
if(le-1!=n-ri)//左右点数不一样绝不可能对称
return false;
for(;le>=1;--le,++ri)
if(!(arr[le].first+arr[ri].first==k&&arr[le].second==arr[ri].second))
return false;
return true;
}