hdu-5762 Teacher Bo(抽屉原理+暴力)

题目链接:

Teacher Bo

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


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
 
题意:
问这些点中是否有两对点他们之间的曼哈顿距离相同;
 
思路:
 
曼哈顿距离最多2*10^5;所以可以暴力找到所有的距离,当时还傻乎乎的想了半天;
 
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>

using namespace std;

#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));

typedef  unsigned long long LL;

template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('
');
}

const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=1000+10;
const double eps=1e-8;

int n,m,vis[2*N];

struct node
{
    int x,y;
}po[N];
int check()
{
    For(i,1,n)
    {
        For(j,i+1,n)
        {
            int dis=abs(po[i].x-po[j].x)+abs(po[i].y-po[j].y);
            if(vis[dis])return 1;
            vis[dis]=1;
        }
    }
    return 0;
}
int main()
{
        int t;
        read(t);
        while(t--)
        {
            read(n);read(m);
            For(i,0,2*m+1)vis[i]=0;
            For(i,1,n)
            {
                read(po[i].x);read(po[i].y);
            }
            if(check())printf("YES
");
            else printf("NO
");
        }
        return 0;
}

  

原文地址:https://www.cnblogs.com/zhangchengc919/p/5709059.html