UVA 1595

来源:互联网 发布:mac 五笔输入法 联想 编辑:程序博客网 时间:2024/05/16 11:21
#include<iostream>#include<vector>#include<string>#include<set>#include<algorithm>  using namespace std;typedef struct Pos{int x;int y;bool operator < (const Pos& p) const {      {}  return x > p.x;}bool operator == (const Pos& p) const { {}return x == p.x&&y==p.y;}}Pos;int main(){int T;cin >> T;while (T--){int N;cin >> N;vector<Pos> v;while (N--){int x, y;cin >> x >> y;Pos p = { 2*x,2*y };v.push_back(p);}int len = v.size();sort(v.begin(), v.end());int sym = (v[0].x + v[len-1].x) / 2;bool flag=true;for (int i = 0;i < len;i++){if (v[i].x == sym)continue;Pos p = { sym - v[i].x + sym,v[i].y };if (find(v.begin(), v.end(), p) == v.end()) { flag = false;break; }}printf("%s\n", flag ? "YES" : "NO");}return 0;}
暴力,对称轴肯定是最右端和最左端的两个点之间,所以直接找到对称点,然后检查其他的点是否都一一对称。为了避免处理小数,所以事先将所有的坐标乘以2
原创粉丝点击