思路:set记录所有点坐标,输入完成后计算对称轴x,判断每个点是否都存在对称点。注意中点可能为浮点数。
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
const int MAXN = 1010;
typedef pair<int, int> point;
int main() {
int T, n;
while (cin >> T) {
while (T--) {
double avgx = 0.0;
set<point> p;
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
avgx += x;
p.insert(point(x, y));
}
avgx = avgx / n;
bool flag = true;
for (set<point>::iterator i = p.begin(); i != p.end(); i++) {
point t = *i;
if (p.find(point(int(2 * avgx - t.first), t.second)) == p.end()) {
flag = false;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}