習題5-6 對稱軸(Symmetry, UVa1595)
阿新 • • 發佈:2019-01-03
//習題5-6 對稱軸(Symmetry, ACM/ICPC Seoul 2004, UVa1595) /* 定義 map<pair<int, int>, int> vis 插入時賦值為1 vis[pair(x, y)]++; 查詢一個關鍵字是否存在:if(!vis[pair<int, int>(x, y)]) ... 如果不存在會新建立一個關鍵字,返回值為0 是否可以等同於if(!vis.count(pair<int, int>(x, y))) ...呢? */ struct A { int x, y; bool operator<(const A &rhs) { return x < rhs.x; } }a[1005]; using PII = pair<int, int>; PII p[1005]; map<PII, int> vis; int main() { int T, n; //IN(); OUT(); scanf("%d", &T); while (T--) { vis.clear(); scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d", &a[i].x, &a[i].y); p[i] = make_pair(a[i].x, a[i].y); if (!vis.count(p[i])) vis[p[i]]++; } sort(a, a + n); int mid = n / 2, s; if (n % 2) s = 2 * a[mid].x; else s = (a[mid].x + a[mid - 1].x); //printf("s = %d\n", s); int x, y; bool flag = true; for (int i = 0; i < n; i++) { x = s - a[i].x; y = a[i].y; //printf("(%d, %d) -> (%d, %d)\n",a[i].x, a[i].y, x, y); if (!vis.count(PII(x, y))) { flag = false; break; } } if (flag) printf("YES\n"); else printf("NO\n"); } return 0; }