hdu 5762 Teacher Bo(鸽巢原理)

来源:互联网 发布:传智播客java课程 编辑:程序博客网 时间:2024/05/22 15:00

思路:虽然有10^5个点,可是两两曼哈顿距离不会超过2*10^5,所以根据鸽巢原理有复杂度为不会超过2*10^5


#include<bits/stdc++.h>using namespace std;#define LL long longconst 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,ACorBD) 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.(T50)

In each test case,the first line contains two intergers, N, M, means the number of points and the range of the coordinates.(N,M105).

Next N lines, the i-th line shows the coordinate of the i-th point.(Xi,Yi)(0Xi,YiM).
 

Output
T lines, each line is "YES" or "NO".
 

Sample Input
23 101 12 23 34 108 82 33 34 4
 

Sample Output
YESNO
 

Source
2016 Multi-University Training Contest 3
 

0 0