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)
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)
.
Output
T
lines, each line is "YES" or "NO".
Sample Input
Sample Output
题意 :给你n个点,找出两个整数对曼哈顿距离相等。。。
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".
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)
2 3 10 1 1 2 2 3 3 4 10 8 8 2 3 3 3 4 4
YES NO
题意 :给你n个点,找出两个整数对曼哈顿距离相等。。。
PS :比赛的时候根本不知道曼哈顿距离是什么。。
百度了一下曼哈顿距离
曼哈顿距离就是两个点在标准坐标系上的绝对轴距总和。。
红线代表曼哈顿距离,绿色代表直线距离,而蓝色和黄色代表等价的曼哈顿距离
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int M=100010;
pair<int,int> iv[M];
int ff[4*M];
int n,m;
int main()
{
int f;
int t;
scanf("%d",&t);
while(t--)
{
f=0;int b;
memset(ff,0,sizeof(ff));
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d%d",&iv[i].first,&iv[i].second);
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
b=abs(iv[i].first-iv[j].first)+abs(iv[i].second-iv[j].second);
if(!ff[b])
{
ff[b]=1;
}
else
{
f=1;
break;
}
}
}
if(f==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}