Teacher Bo
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 205 Accepted Submission(s): 118
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 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”.
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
2
3 10
1 1
2 2
3 3
4 10
8 8
2 3
3 3
4 4
Sample Output
YES
NO
题意:给你n个点,让你找两个数对,
A,B
和
C,D
,使得
A
和
思路:因为点坐标的范围为
105
,所以说,两个点的曼哈顿距离最多只有
2∗105
,,所以说暴力枚举的复杂度也是
2∗105
,是可以接受的.
ac代码:
/* ***********************************************
Author : AnICoo1
Created Time : 2016-07-26-17.42 Tuesday
File Name : D:\MyCode\2016-7-26\1.cpp
LANGUAGE : C++
Copyright 2016 clh All Rights Reserved
************************************************ */
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
struct s
{
int x,y;
}p[MAXN];
int v[MAXN];
int main()
{
int t;scanf("%d",&t);
while(t--)
{
int bz=0;
mem(v);int n,m;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 k=abs(p[i].x-p[j].x)+abs(p[i].y-p[j].y);
if(!v[k])
v[k]=1;
else
{
bz=1;
break;
}
}
if(bz) break;
}
if(bz) printf("YES\n");
else printf("NO\n");
}
return 0;
}