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,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
 
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;
}

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

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

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

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

  6. HDU 5762 Teacher Bo ( 暴力 )

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

  7. HDU 5762

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

  8. hdu 5761 Rowe Bo 微分方程

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

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

    题目链接: Teacher Bo Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

随机推荐

  1. tornado解析http body的过程分析

    tornado解析http body的过程分析 在最近写的一个RESTful API Server过程中,发现tornaod对解析POST BODY的内容有限制. 而在以前用web.py则没有这个限制 ...

  2. POJ3126Prime Path

    http://poj.org/problem?id=3126 题意 : 给你两个四位数,都是素数,一个是初始素数x,一个是目标素数y,让你从x变成y,x每次只能改变1位数,来变成另外一个素数k,再改变 ...

  3. [Ruby on Rails系列]6、一个简单的暗语生成器与解释器(上)

    [0]Ruby on Rails 系列回顾 [Ruby on Rails系列]1.开发环境准备:Vmware和Linux的安装 [Ruby on Rails系列]2.开发环境准备:Ruby on Ra ...

  4. 深入浅出Java并发包—原子类操作

    我们知道,JDK1.5以后引入了并发包(java.util.concurrent)用于解决多CPU时代的并发问题,而并发包中的类大部分是基于Queue的并发类,Queue在大多数情况下使用了原子类(A ...

  5. [YY题]HDOJ5288 OO’s Sequence

    题意:求这个式子 $\sum \limits_{i=1}^{n} \sum \limits_{j=1}^{m} f(i, j) mod (10^9 + 7)$ 的值 就是对每个区间[i, j]枚举区间 ...

  6. python自定义函数在Python解释器中调用

    https://docs.python.org/2.7/tutorial/modules.html Modules If you quit from the Python interpreter an ...

  7. 2、JPA的HelloWorld

    这一节写一个JPA的HelloWorld来体验一下. 一.建立工程 按照 1.创建一个JPA project(解决“at least one user library must be selected ...

  8. testNG小试牛刀

    testNG是一个测试框架,其灵感来自JUnit和NUnit的,但引入了一些新的功能,使其功能更强大,使用更方便. testNG是一个开源自动化测试框架:testNG表示下一代. testNG是类似于 ...

  9. wordCount程序中MapReduce工作过程分析

    Map处理的是一个纯文本.Mapper处理的数据是由InputFormat分解过的数据集,其中InputFormat的作用是将数据集切割成小数据集InputSplit,每一个InputSplit将由一 ...

  10. 【问底】徐汉彬:Web系统大规模并发——电商秒杀与抢购

    [导读]徐汉彬曾在阿里巴巴和腾讯从事4年多的技术研发工作,负责过日请求量过亿的Web系统升级与重构,目前在小满科技创业,从事SaaS服务技术建设. 电商的秒杀和抢购,对我们来说,都不是一个陌生的东西. ...