思路:虽然有10^5个点,可是两两曼哈顿距离不会超过2*10^5,所以根据鸽巢原理有复杂度为不会超过2*10^5
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 1e5+7;
struct point
{
int x, y;
}p[maxn];
int vis[2*maxn];
int Dist(point a,point b)
{
int dist = abs(a.x - b.x) + abs(a.y - b.y);
return dist;
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
int n, m, flag = 0;
memset(vis,0,sizeof(vis));
scanf("%d%d",&n,&m);
for(int i = 0;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
int d = Dist(p[i], p[j]);
if (!vis[d])
vis[d] = 1;
else
{
flag = 1;
break;
}
}
}
if (flag == 1)
cout << "YES" << endl;
else cout << "NO" << endl;
}
}
Problem Description
Teacher BoBo is a geography teacher in the school.One day in his class,he marked
N
points in the map,the
i
-th point is at
(Xi,Yi)
.He wonders,whether there is a tetrad
(A,B,C,D)(A<B,C<D,A≠CorB≠D)
such that the manhattan distance between A and B is equal to the manhattan distance between C and D.
If there exists such tetrad,print "YES",else print "NO".
If there exists such tetrad,print "YES",else print "NO".
Input
First line, an integer
T
. There are
T
test cases.
(T≤50)
In each test case,the first line contains two intergers, N, M, means the number of points and the range of the coordinates. (N,M≤105) .
Next N lines, the i -th line shows the coordinate of the i -th point. (Xi,Yi)(0≤Xi,Yi≤M) .
In each test case,the first line contains two intergers, N, M, means the number of points and the range of the coordinates. (N,M≤105) .
Next N lines, the i -th line shows the coordinate of the i -th point. (Xi,Yi)(0≤Xi,Yi≤M) .
Output
T
lines, each line is "YES" or "NO".
Sample Input
2 3 10 1 1 2 2 3 3 4 10 8 8 2 3 3 3 4 4
Sample Output
YES NO
Source