• HDU 5762 Teacher Bo


    Teacher Bo

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


    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
     
    Source
     
     
     
    解析:因为曼哈顿距离最多有2*M种,可以枚举点对之间的曼哈顿距离,并用一个bool数组记录每种距离是否出现过,枚举时如果发现重复就输出"YES",否则输出"NO"。乍一看,时间复杂度是O(N2),实际上最多循环min{2*M, N*(N-1)/2}次,时间复杂度为O(min{M, N2})。
     
     
     
    #include <bits/stdc++.h>
    using namespace std;
    
    pair<int, int> p[100005];
    bool vis[200005];
    
    void solve(int n, int m)
    {
        memset(vis, 0, sizeof(vis));
        for(int i = 0; i < n; ++i){
            for(int j = i+1; j < n; ++j){
                int dis = abs(p[i].first-p[j].first)+abs(p[i].second-p[j].second);
                if(vis[dis]){
                    puts("YES");
                    return;
                }
                else
                    vis[dis] = true;
            }
        }
        puts("NO");
    }
    
    int main()
    {
        int t, n, m;
        scanf("%d", &t);
        while(t--){
            scanf("%d%d", &n, &m);
            for(int i = 0; i < n; ++i)
                scanf("%d%d", &p[i].first, &p[i].second);
            solve(n, m);
        }
        return 0;
    }
    
  • 相关阅读:
    汉字编码问题
    C语言创建UTF8编码文本文件
    Know more about shared pool subpool
    SCN Headroom与时光倒流到1988年的Oracle数据库
    Know more about Enqueue Deadlock Detection
    11g新特性:RDBMS Component TRACE
    了解你所不知道的SMON功能(十一):OFFLINE UNDO SEGMENT
    了解11g OCM
    Bulk Collect/FORALL的性能测试
    【推荐】DBA必须了解的11g中的一些变化
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/5711779.html
Copyright © 2020-2023  润新知