zoukankan      html  css  js  c++  java
  • HDU 5762

    Teacher Bo

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1052    Accepted Submission(s): 582

    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
    2
    3 10
    1 1
    2 2
    3 3
    4 10
    8 8
    2 3
    3 3
    4 4
     
    Sample Output
    YES
    NO
     
    Author
    绍兴一中
     
    Source
     
    Recommend
    wange2014   |   We have carefully selected several similar problems for you:  5792 5791 5790 5789 5788 
    题意:
    给出若干组点的坐标,求这中间有没有两组曼哈顿距离相同的坐标。
    思路:
    题目中X,Y都小于M,就可以用每一种曼哈顿距离作为数组的下标,并把数组标记为1,暴力出数组值为1的那个下标值,就找出了相同的。
     代码:
     1 #include<iostream>
     2 #include<string>
     3 #include<cstdio>
     4 #include<cmath>
     5 #include<cstring>
     6 #include<algorithm>
     7 #include<vector>
     8 #include<iomanip>
     9 #include<queue>
    10 using namespace std;
    11 struct point
    12 {
    13     int x,y;
    14 };
    15 int main()
    16 {
    17     int n,m,t;
    18     cin>>t;
    19     while(t--)
    20     {
    21         point p[100005];
    22         int dis[100005];
    23         cin>>n>>m;
    24         for(int i=0;i<n;i++)
    25         {
    26             cin>>p[i].x>>p[i].y;
    27         }
    28         int flag=0;
    29         memset(dis,0,sizeof(dis));
    30         for(int i=0;i<n;i++)
    31         {
    32             for(int j=i+1;j<n;j++)
    33             {
    34                 int tem=abs(p[i].x-p[j].x)+abs(p[i].y-p[j].y);
    35                 if(dis[tem]==1)
    36                 {
    37                     flag=1;
    38                     break;
    39                 }
    40                 dis[tem]=1;
    41             }
    42             if(flag==1)
    43             {
    44                 cout<<"YES"<<endl;
    45                 break;
    46             }
    47         }
    48         if(flag==0) cout<<"NO"<<endl;
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    内存泄露了么: Handlers & Inner Classes
    SVN update: 'skipped' message
    Eclipse Java注释模板设置详解
    Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported
    简单的SocketExample
    Struts2+JSON+JQUERY DEMO
    Checked&Unchecked Exception
    js垃圾回收机制
    Vue中路由守卫
    Vue中Watch和Computed的差异
  • 原文地址:https://www.cnblogs.com/--ZHIYUAN/p/5733028.html
Copyright © 2011-2022 走看看