Teacher Bo HDU

来源:互联网 发布:python math 编辑:程序博客网 时间:2024/05/29 08:28
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

题意 :给你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;}




原创粉丝点击