给出平面上N(N≤1000)个点,问是否可以找到一条竖线,使得所有点左右对称。例如
图中,左边的图形有对称轴,右边没有。
第一眼看上去没什么思路,感觉挺难的后来看了别人的发现确实不难
对称轴 显然是在(maxnum + minnum ) / 2上
所以我们只需要判断每个 x+(maxnum + minnum ) / 2 ,y 在数轴行是否存在 就可以知道了
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
struct node
{
int x,y;
node(int x,int y):x(x),y(y)
{
}
bool operator < (const node & a) const
{
if(x == a.x)
{
return y<a.y;
}
return x<a.x;
}
};
set<node>s;
int t,x,y,n;
int main(void)
{
ios::sync_with_stdio(false);
cin>>t;
while(t--)
{
cin>>n;
s.clear();
for(int i = 0;i<n;i++){
cin>>x>>y;
s.insert(node(x,y));
}
x = s.begin()->x;
x += s.rbegin()->x;
bool flag = true;
for(auto & u : s){
if(s.find(node(x-u.x,u.y)) == s.end())
{
flag = false;break;
}
}
if(flag )cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}