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. linux下面覆盖文件,如何实现直接覆盖,不提示

    转自:http://w-tingsheng.blog.163.com/blog/static/2505603420124309130528/ cp覆盖时,无论加什么参数-f之类的还是提示是否覆盖,当文 ...

  2. javascript滚动条之ScrollBar.js

    ScrollBar.js是一个仅仅120行的滚动条JS插件,使用非常方便 详情阅读:https://git.oschina.net/wuquanyao/scrollbar.js/*========== ...

  3. Rescue

    1039: Rescue Time Limit: 1 Sec  Memory Limit: 32 MBSubmit: 1320  Solved: 306 Description Angel was c ...

  4. cocos基础教程(11)事件分发机制

    cocos3.0的事件分发机制: 创建一个事件监听器-用来实现各种触发后的逻辑. 事件监听器添加到事件分发器_eventDispatcher,所有事件监听器有这个分发器统一管理. 事件监听器有以下几种 ...

  5. 入门必看--JavaScript基础

    JavaScript他是一种描述性语言,其实他并不难学,只要用心学,一定会学好,我相信大家在看这篇文章的时候,一定也学过HTML吧,使用JavaScript就是为了能和网页有更好的交互,下面切入主题. ...

  6. Windows程序----初识Windows程序

    先来看一些励志名言来激励一下自己吧!  励志名言:每一发奋发奋的背后,必有加倍的赏赐 1.有无目标是成功者与平庸者的根本差别. 2.成功不是将来才有的,而是从决定去做的那一刻起,持续累积而成. 3.当 ...

  7. Nginx反向代理 负载均衡

    nginx 这个轻量级.高性能的 web server 主要可以干两件事情: 〉直接作为http server(代替apache,对PHP需要FastCGI处理器支持): 〉另外一个功能就是作为反向代 ...

  8. Linux下安装配置MongoDB 3.0.x 版本数据库

    说明: 操作系统:CentOS 5.X 64位 IP地址:192.168.21.128 实现目的: 安装配置MongoDB数据库 具体操作: 一.关闭SElinux.配置防火墙 1.vi /etc/s ...

  9. unity3d 加密资源并缓存加载

    原地址:http://www.cnblogs.com/88999660/archive/2013/04/10/3011912.html 首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止 ...

  10. HDOJ 1590

    #include<stdio.h> #include<iostream> #include<stdlib.h> #include<string.h> u ...