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. auto_ptr的设计动机

    auto_ptr的设计动机 C++标准程序库提供的auto_ptr是一种智能型指针(smart pointer),帮助程序员防止“被异常抛出时发生资源泄露”. 函数的操作经常依以下模式进行: 1.获取 ...

  2. POJ 1775

    #include <iostream> using namespace std; ,,,,,,,,,}; bool boo; void DFS(int time,int sum); int ...

  3. JsRender系列demo(5) for else

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  4. Android面试题基础(转)

    71道经典Android面试题和答案 1.下列哪些语句关于内存回收的说明是正确的? (b ) A. 程序员必须创建一个线程来释放内存 B.内存回收程序负责释放无用内存 C.内存回收程序允许程序员直接释 ...

  5. VBScript 函数

    Date/Time 函数 Conversion 函数 Format 函数 Math 函数 Array 函数 String 函数 其他函数 Date/Time 函数 函数 描述 CDate 把一个有效的 ...

  6. activiti5.13 框架 数据库设计说明书

    转载自:http://www.cnblogs.com/llzgzljl/p/3356108.html activiti5.13 框架 数据库设计说明书 1.结构设计 1.1.    逻辑结构设计 Ac ...

  7. 对象的类型转换P109

    类作为一种应用数据类型,和基本数据类型的变量一样.不同类中存在对象与对象之间的类型转问题,对象的类型转换只能在  具有继承关系的 父类对象-----子类对象 之间进行   子类通常比父类拥有更多的域和 ...

  8. Javaweb实现的优优图书商城(含源码)

    原文地址:http://www.cnblogs.com/liaoyu/p/uushop.html 源码地址:https://github.com/liaoyu/uushop 贴出一个大学时做的小项目, ...

  9. highcharts 结合phantomjs纯后台生成图片系列二之php2

    上篇文章中介绍了phantomjs的使用场景,方法. 本篇文章详细介绍使用php,highcharts 结合phantomjs纯后台生成图片.包含一步步详细的php代码 一.highcharts 结合 ...

  10. LingPipe-TextClassification(文本分类)

    What is Text Classification? Text classification typically involves assigning a document to a catego ...