hdu5762 Teacher Bo (暴力)

Teacher Bo
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 205 Accepted Submission(s): 118

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 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.(T≤50)

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

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

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

题意:给你n个点,让你找两个数对, A,B C,D ,使得 A B的曼哈顿距离等于 C D的曼哈顿距离,问是否存在这样的对, A!=C B!=D .

思路:因为点坐标的范围为 105 ,所以说,两个点的曼哈顿距离最多只有 2105 ,,所以说暴力枚举的复杂度也是 2105 ,是可以接受的.
ac代码:

/* ***********************************************
Author       : AnICoo1
Created Time : 2016-07-26-17.42 Tuesday
File Name    : D:\MyCode\2016-7-26\1.cpp
LANGUAGE     : C++
Copyright  2016 clh All Rights Reserved
************************************************ */
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
struct s
{
    int x,y;
}p[MAXN];
int v[MAXN];
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        int bz=0;
        mem(v);int n,m;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 k=abs(p[i].x-p[j].x)+abs(p[i].y-p[j].y);
                if(!v[k])
                    v[k]=1;
                else
                {
                    bz=1;
                    break;
                }
            }
            if(bz) break;
        }
        if(bz) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值