UVa 1595 Symmetry [Ad Hoc]

来源:互联网 发布:丰达财富网络借贷 编辑:程序博客网 时间:2024/06/17 07:09

Description

给你N个点的坐标(X,Y)
判断这这些点是否存在一个垂直于X轴的对称轴

Algorithm

目前只知道用set做
set可以存对(pair)
不可以存结构体(struct)
然后就是把每个点对存到set里,然后找有没有对称的就可以了
对称轴使用最大X坐标和最小X坐标加起来搞得

Code

#include <iostream>#include <cstdio>#include <climits>#include <cstring>#include <set>using namespace std;const int MAXL = 20000 + 9;const int INF = INT_MAX;typedef pair<int, int> V;void solve(){  set<V> myset;  int n;  scanf("%d", &n);  int minx = INF;  int maxx = -INF;  while (n--) {    int x, y;    scanf("%d%d", &x, &y);    minx = min(minx, x);    maxx = max(maxx, x);    myset.insert(V(x, y));  }  int mid2 = maxx + minx;  bool flag = true;  for (set<V>::iterator it = myset.begin(); it != myset.end(); it++) {    if (!myset.count(V(mid2- (*it).first, (*it).second))) {      flag = false;      break;    }  }  if (flag) {    puts("YES");  } else  {    puts("NO");  }}int main(){  //freopen("in.txt", "r", stdin);  int t;  scanf("%d", &t);  while (t--) {    solve();  }}
0 0