HDU 5762:曼哈顿距离
来源:互联网 发布:java行业发展前景 编辑:程序博客网 时间:2024/05/18 03:59
Problem Description
Teacher BoBo is a geography teacher in the school.One day in his class,he markedN 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".
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, thei -th line shows the coordinate of the i -th point.(Xi,Yi)(0≤Xi,Yi≤M) .
In each test case,the first line contains two intergers, N, M, means the number of points and the range of the coordinates.
Next N lines, the
Output
Sample Input
23 101 12 23 34 108 82 33 34 4
Sample Output
YESNO
分析:这个题主要是要知道曼哈顿距离的意思,曼哈顿距离(Manhattan Distance)是由十九世纪的赫尔曼·闵可夫斯基所创词汇 ,是种使用在几何度量空间的几何学用语,用以标明两个点上在标准坐标系上的绝对轴距总和。然后hash一下就解决了。
AC代码:
#include<iostream>#include<cstdio>#include<cmath>#include<string.h>#include<algorithm>using namespace std;struct Point{ int x; int y;};Point point[100010];bool ans[10000000];int main(){ int T; scanf("%d",&T); while(T--) { int N,M; scanf("%d%d",&N,&M); for(int i=1;i<=N;i++) scanf("%d%d",&point[i].x,&point[i].y); memset(ans,0,sizeof(ans)); int flag=0; for(int i=1;i<=N-1;i++) { for(int j=i+1;j<=N;j++) { int dis=abs(point[i].x-point[j].x)+abs(point[i].y-point[j].y); if(ans[dis]) { flag=1; cout<<"YES"<<endl; break; } ans[dis]=true; } if(flag) break; } if(flag==0) cout<<"NO"<<endl; } return 0;}
阅读全文
0 0
- HDU 5762:曼哈顿距离
- HDU-4666 最远曼哈顿距离
- Hdu-4666 Hyperspace(曼哈顿距离)
- hdu-4666-Hyperspace-最长曼哈顿距离
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- hdu 4666 Hyperspace (曼哈顿距离+set )
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- HDU 4666 Hyperspace(最长曼哈顿距离)
- hdu 4666 线段树+最大曼哈顿距离
- HDU 4543|三足鼎立|曼哈顿距离|二分答案
- 曼哈顿距离
- 曼哈顿距离
- 曼哈顿距离
- 曼哈顿距离
- 曼哈顿距离
- HDU 4666 Hyperspace【最远曼哈顿距离+优先队列】
- hdu 4666 (经典求曼哈顿距离 + multiset容器)
- HDU 4666 经典的求最远曼哈顿距离
- halocn读取本地文件
- 存储过程
- 文件头
- 数据传输加密非对称加密算法以及对称算法-RSA+AES
- java鬼混笔记:Eclipse 远程调试 window+tomcat版
- HDU 5762:曼哈顿距离
- Java并发编程:Lock
- Hadoop入门第四篇:手动搭建自己的hadoop小集群
- 常用的时间序列算法模型
- 表空间详解
- 九九乘法表
- 【单片机笔记】51串口printf的使用和变量循环问题
- 【Android自定义View】仿Photoshop取色器ColorPicker(三)
- 网页全屏看视频时去掉左下角“正在加载...”提示的方法