本篇题解本来写于洛谷,但是洛谷的格式审查严格(仅本人查看)故再写于csdn
1.由于对称轴垂直于x轴因此每个点的x坐标排序去重后按照奇偶数分开讨论. 2.奇数x坐标对称轴在中间点上. 3.偶数x坐标对称轴不在任何点上是一个浮点值. 4.预存每个点的xy坐标到set中,方便按照2,3划分的坐标轴情况遍历每个点是否存在对称点.
void solve(){
int T;
cin >> T;
while(T--){
int n;
cin >> n;
vector<pii> a(n);
vi ax;
set<pii> S;
rep(i, n){
cin >> a[i].first >> a[i].second;
S.insert(a[i]);
ax.push_back(a[i].first);
}
sort(ax.begin(), ax.end());
int axsize = unique(ax.begin(), ax.end()) - ax.begin();
sort(a.begin(), a.end(), [](pii& p1, pii& p2){
return p1.first != p2.first ? p1.first < p2.first : p1.second < p2.second;
});
if(axsize % 2 == 0){
double sx;
sx = (ax[(axsize-1) / 2] + ax[(axsize-1) / 2 + 1]) / 2.0;
int idx = lower_bound(a.begin(), a.end(), sx, [](const pii &p, double v){
return p.first < v;
}) - a.begin();
int find = 1;
rep(i, idx+1){
int nx = 2*sx - a[i].first, ny = a[i].second;
if(!S.count(make_pair(nx, ny))){
find = 0;
break;
}
}
if(find) cout << "YES" << endl;
else cout << "NO" << endl;
}
else{
int sx = ax[(axsize-1) / 2];
int idx = lower_bound(a.begin(), a.end(), sx, [](const pii &p, int v){
return p.first < v;
}) - a.begin();
int find = 1;
rep(i, idx){
int nx = 2*sx - a[i].first, ny = a[i].second;
if(!S.count(make_pair(nx, ny))){
find = 0;
break;
}
}
if(find) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
}
int main(){
#ifndef DEBUG
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
#ifdef LOCAL
freopen("in", "r", stdin);
freopen("o", "w", stdout);
#endif
// cout << setiosflags(ios::fixed);
// cout << setprecision(2);
// cout << setw(2) << setfill('0'); // add this every time when cout int with width and left padding '0'
solve();
return 0;
}