很水的一道题 , 只是忘记 set 数组忘记清空,wa 了
题目清楚,找一条竖线,判断是否对称,输入的时候就找到对称轴的 x 坐标,当然 为了防止除法出错,可以对每点坐标进行 *2 处理
#include<iostream>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
typedef pair<int, int> point;
set<point> a;
int n, t;
void init() {
t = 0;
a.clear();
int x, y;
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d%d", &x, &y);
t += x;
a.insert(point(x*n,y));
}
t *= 2;
}
void solve() {
for(set<point>::iterator i = a.begin(); i != a.end(); ++i) {
point p = *i;
//cout << p.first << "==" << p.second << endl;
if(a.find(point(t-p.first, p.second )) == a.end() ) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
int main() {
int T;
scanf("%d", &T);
while(T--) {
init();
solve();
}
return 0;
}