HDU 5762 Teacher Bo (暴力)
Teacher Bo
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5762
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
2016 Multi-University Training Contest 3
##题意:
给出平面上的N个点,求是否一个四元组(A,B,C,D)满足A\B之间的曼哈顿距离等于C\D之间距离.
条件(A
##题解:
这个题让我懵比的两个小时...
一开始先把曼哈顿距离想成了abs(dx+dy),然后可以只考虑每个点的坐标和,从而误把题目转化为求一个数组中是否有两对数的和相等.
由于规模是1e5,然后一直在想O(nlogn)的算法...
首先,曼哈顿距离的正确定义是abs(dx)+abs(dy).
其次,题目的数据规模确实不能跑O(n^2)的算法,但是题目限制了坐标的范围为[0,1e5], 这意味着任意两点的曼哈顿距离只可能有2e5种可能,暴力最多只会判断2e5个组合,所以不会超时.
所以直接暴力判断所有组合即可,当出现重复的距离时停止判断(先离线数据).
这个题懵比这么久真的是非常不应该,所以以后卡题的时候,一定要重新读题和尝试转换思考角度.
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 251000
#define mod 100000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n,m;
struct point {
int x,y;
}p[maxn];
bool dis[maxn];
int get_ans(point a, point b) {
return abs(a.x-b.x) + abs(a.y-b.y);
}
int main(int argc, char const *argv[])
{
//IN;
int t; cin >> t;
while(t--)
{
memset(dis, 0, sizeof(dis));
cin >> n >> m;
int flag = 0;
for(int i=1; i<=n; i++) {
int x,y; scanf("%d %d", &x,&y);
p[i].x=x; p[i].y=y;
}
for(int i=1; i<=n; i++) {
for(int j=1; j<i; j++) {
int tmp = get_ans(p[i],p[j]);
if(dis[tmp]) {
flag = 1;
break;
}
dis[tmp] = 1;
}
if(flag) break;
}
if(flag) puts("YES");
else puts("NO");
}
return 0;
}
HDU 5762 Teacher Bo (暴力)的更多相关文章
- hdu 5762 Teacher Bo 暴力
Teacher Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...
- hdu 5762 Teacher Bo 曼哈顿路径
Teacher Bo Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tota ...
- HDU 5762 Teacher Bo
Teacher Bo Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tota ...
- HDU 5762 Teacher Bo ( 暴力 )
链接:传送门 题意:给出N个点( Xi , Yi ),和点的最远位置M,询问是否有这样的四个点 (A,B,C,D)(A<B,C<D,A≠CorB≠D) ,AB的曼哈顿路径长度等于CD的曼哈 ...
- 【模拟】HDU 5762 Teacher Bo
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 题目大意: 给n个点,坐标范围0~m(n,m<=105),求是否存在2个点对满足哈夫曼距 ...
- HDU 5762 Teacher Bo (鸽笼原理) 2016杭电多校联合第三场
题目:传送门. 题意:平面上有n个点,问是否存在四个点 (A,B,C,D)(A<B,C<D,A≠CorB≠D)使得AB的横纵坐标差的绝对值的和等于CD的横纵坐标差的绝对值的和,n<1 ...
- hdu-5762 Teacher Bo(抽屉原理+暴力)
题目链接: Teacher Bo Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2016 Multi-University Training Contest 3-1011.Teacher Bo,暴力!
Teacher Bo Time Limit: 4000/2000 MS (Java/Ot ...
- HDU 5762
Teacher Bo Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tot ...
随机推荐
- IntelliJ IDEA For Mac 快捷键——常用版
一.搜索 搜索文件 command+shift+n 打开方法实现类 command+option+b 全文搜索 ctrl+shift+f (1)类和方法 查看类的继承结构 ctrl+h 查看方法的 ...
- hdu 4973 A simple simulation problem. (线段树)
题目链接 题意: 给定n长的序列 m个操作 序列默认为 1, 2, 3···n 操作1:D [l,r] 把[l,r]区间增长 :( 1,2,3,4 进行 D [1,3]变成 1,1,2,2,3,3,4 ...
- Android中View转换为Bitmap及getDrawingCache=null的解决方法
1.前言 Android中经常会遇到把View转换为Bitmap的情形,比如,对整个屏幕视图进行截屏并生成图片:Coverflow中需要把一页一 页的view转换为Bitmap.以便实现复杂的图形效果 ...
- if(username.equals(“zxx”){}
1. if(username.equals(“zxx”){} username可能为NULL,会报空指针错误:改为"zxx".equals(username) 2. int x ...
- bzoj4044
这题简直了………… 首先根据操作可知,我们肯定是先造出某个偶数长度的回文串,然后添加若干字符得到设回文串长为len[x] 则ans=min(n-len[x]+f[x]); 那么问题就是制造这个串的回文 ...
- QQ在线图标 离线 QQ开通在线QQ服务 QQ陌生人直接聊天
如图 永远都显示离线,即使QQ在线也显示离线的原因和解决方法 1:打开 这个页面 提示你开通 你就点击一下开通 这样头像就可以正常显示 离线 和在线了 http://wp.q ...
- POI读取Word与Excel
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; ...
- 在Windows下编译FFmpeg详细说明
MinGW:一个可自由使用和自由发布的Windows特定头文件和使用GNC工具集导入库的集合,允许你生成本地的Windows程序而不需要第三方C运行时 MinGW,即 Minimalist GNU F ...
- Android 使用库项目时的一个特殊tip
前提: 项目A作为库项目被项目B引用,但是项目A中有自定义的控件和自定义的属性,当在项目B中使用自定义的属性时,编译时就会直接报错:No resource identifier found for a ...
- 学习Mongodb(一)
图片摘录自陈彦铭出品2012.5的<10天掌握MongDB> MongoDB的特点--->面向集合存储,易于存储对象类型的数据--->模式自由--->支持动态查询---& ...