Description
给定
n
个点,求是否存在两对点曼哈顿距离相等。
Solution
曼哈顿距离的个数应该也是 O(n) 的啦。。。
#include <bits/stdc++.h>
using namespace std;
const int N = 201010;
inline char get(void) {
static char buf[100000], *S = buf, *T = buf;
if (S == T) {
T = (S = buf) + fread(buf, 1, 100000, stdin);
if (S == T) return EOF;
}
return *S++;
}
inline void read(int &x) {
static char c; x = 0;
for (c = get(); c < '0' || c > '9'; c = get());
for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
}
int test, n, m, d, ans;
struct Point {
int x, y;
Point (int _x = 0, int _y = 0):x(_x), y(_y) {}
};
Point a[N];
int vis[N];
inline int Dis(Point &a, Point &b) {
return fabs(a.x - b.x) + fabs(a.y - b.y);
}
int main(void) {
freopen("1.in", "r", stdin);
read(test);
for (int t = 1; t <= test; t++) {
read(n); read(m); ans = 0;
for (int i = 1; i <= n; i++) {
read(a[i].x); read(a[i].y);
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
d = Dis(a[i], a[j]);
if (vis[d] == t) {
ans = 1; break;
}
vis[d] = t;
}
if (ans) break;
}
puts(ans ? "YES" : "NO");
}
}