Teacher Bo

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

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,A≠CorB≠D) 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
#include<iostream>
#include<stdio.h>
#include<set>
#include<math.h>
using namespace std;
const int maxx = ;
set<int> hav;
int px[maxx];
int py[maxx];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
hav.clear();
scanf("%d%d",&n,&m);
for(int i=; i<n; i++ )
{
scanf("%d%d",px+i,py+i);
}
int flag=;
for(int i=; i<n-; i++)
{
for(int j=i+; j<n; j++)
{
int dis=abs(px[j]-px[i])+abs(py[j]-py[i]);
if(hav.count(dis))
{
flag=;
break;
}
else
{
hav.insert(dis);
}
}
if(flag)
{
break;
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
}
考虑一种暴力,每次枚举两两点对之间的曼哈顿距离,并开一个桶记录每种距离是否出现过,如果某次枚举出现了以前出现的距离就输 YESYES ,否则就输 NONO .

注意到曼哈顿距离只有 O(M)O(M) 种,根据鸽笼原理,上面的算法在 O(M)O(M) 步之内一定会停止.所以是可以过得.

一组数据的时间复杂度 O(\min{N^,M})O(min{N^​​ ,M}) .

hdu 5762 Teacher Bo 曼哈顿路径的更多相关文章

  1. HDU 5762 Teacher Bo (暴力)

    Teacher Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...

  2. hdu 5762 Teacher Bo 暴力

    Teacher Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...

  3. HDU 5762 Teacher Bo

    Teacher Bo Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tota ...

  4. HDU 5762 Teacher Bo ( 暴力 )

    链接:传送门 题意:给出N个点( Xi , Yi ),和点的最远位置M,询问是否有这样的四个点 (A,B,C,D)(A<B,C<D,A≠CorB≠D) ,AB的曼哈顿路径长度等于CD的曼哈 ...

  5. 【模拟】HDU 5762 Teacher Bo

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 题目大意: 给n个点,坐标范围0~m(n,m<=105),求是否存在2个点对满足哈夫曼距 ...

  6. HDU 5762 Teacher Bo (鸽笼原理) 2016杭电多校联合第三场

    题目:传送门. 题意:平面上有n个点,问是否存在四个点 (A,B,C,D)(A<B,C<D,A≠CorB≠D)使得AB的横纵坐标差的绝对值的和等于CD的横纵坐标差的绝对值的和,n<1 ...

  7. 2016 Multi-University Training Contest 3-1011.Teacher Bo,暴力!

    Teacher Bo                                                         Time Limit: 4000/2000 MS (Java/Ot ...

  8. HDU 5762

    Teacher Bo Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tot ...

  9. hdu 5761 Rowe Bo 微分方程

    1010 Rower Bo 首先这个题微分方程强解显然是可以的,但是可以发现如果设参比较巧妙就能得到很方便的做法. 先分解v_1v​1​​, 设船到原点的距离是rr,容易列出方程 \frac{ dr} ...

随机推荐

  1. php 开启curl,重启php-fpm服务

    1,找到php.ini配置 find / -name 'php.ini' /usr/local/php/etc/php.ini 找到extension=php_curl.dll 把前面的分号去掉即可. ...

  2. linux学习笔记 2013-09-02

    1,解压一个tar.gz文件夹 tar -xvzf  filename.tar.gz 2,删除一个文件夹下所有的文件 rm -rf * 3,安装文件 sudo apt-get install XXX. ...

  3. <转>错误 x error LNK1104: 无法打开文件“E:\xxxx\Debug\xxxx.exe”

    刚刚还好好的,怎么突然就出现这样的错误, 后来分析原因, 第一:查看那个exe文件是否存在, 第二:查看那个文件或者那个文件所在的文件夹是否打开或者改名字等等操作占用着这个文件. 第三:重新清理并生成 ...

  4. [codeforces 260]B. Ancient Prophesy

    [codeforces 260]B. Ancient Prophesy 试题描述 A recently found Ancient Prophesy is believed to contain th ...

  5. haartraining生成.xml过程

    继续向大神学习http://www.cnblogs.com/tornadomeet/archive/2012/03/28/2420936.html

  6. Python 正则表达式_re模块_使用compile加速

    使用compile加速 compile( rule [,flag] ) 将正则规则编译成一个Pattern对象,以供接下来使用. 第一个参数是规则式,第二个参数是规则选项. 返回一个Pattern对象 ...

  7. WordPress前台后台页面打开慢的解决方法

    写个人网站用WordPress程序是一个不错的选择,但是目前安装之后速度很慢,后台配置页面半天打不开,在网上查了一下原来是Google被墙导致,WordPress默认模板会加载谷歌的open-sans ...

  8. Light OJ 1253 Misere Nim (尼姆博弈(2))

    LightOJ1253 :Misere Nim 时间限制:1000MS    内存限制:32768KByte   64位IO格式:%lld & %llu 描述 Alice and Bob ar ...

  9. [Android Pro] proguard.cfg 配置文件

    转载自:http://my.oschina.net/zhangzhihao/blog/72393 # ------------------------------------- # android 原 ...

  10. [Android Pro] android Flag介绍

    一些Flag的介绍 窗口之后的内容变暗. public static final int FLAG_DIM_BEHIND       = 0x00000002; 窗口之后的内容变模糊. public ...