HDU 5762:曼哈顿距离
2017-08-19 13:33
239 查看
[align=left]Problem Description[/align]
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".
[align=left] [/align]
[align=left]
[/align]
[align=left]Input[/align]
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).
[align=left] [/align]
[align=left]
[/align]
[align=left]Output[/align]
T
lines, each line is "YES" or "NO".
[align=left] [/align]
[align=left]
[/align]
[align=left]Sample Input[/align]
2
3 10
1 1
2 2
3 3
4 10
8 8
2 3
3 3
4 4
[align=left] [/align]
[align=left]Sample Output[/align]
YES
NO
[align=left][/align]
[align=left]分析:这个题主要是要知道曼哈顿距离的意思,曼哈顿距离(Manhattan Distance)是由十九世纪的赫尔曼·闵可夫斯基所创词汇 ,是种使用在几何度量空间的几何学用语,用以标明两个点上在标准坐标系上的绝对轴距总和。然后hash一下就解决了。[/align]
[align=left]
[/align]
[align=left]AC代码:[/align]
[align=left][/align]
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".
[align=left] [/align]
[align=left]
[/align]
[align=left]Input[/align]
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).
[align=left] [/align]
[align=left]
[/align]
[align=left]Output[/align]
T
lines, each line is "YES" or "NO".
[align=left] [/align]
[align=left]
[/align]
[align=left]Sample Input[/align]
2
3 10
1 1
2 2
3 3
4 10
8 8
2 3
3 3
4 4
[align=left] [/align]
[align=left]Sample Output[/align]
YES
NO
[align=left][/align]
[align=left]分析:这个题主要是要知道曼哈顿距离的意思,曼哈顿距离(Manhattan Distance)是由十九世纪的赫尔曼·闵可夫斯基所创词汇 ,是种使用在几何度量空间的几何学用语,用以标明两个点上在标准坐标系上的绝对轴距总和。然后hash一下就解决了。[/align]
[align=left]
[/align]
[align=left]AC代码:[/align]
#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; }
[align=left][/align]
相关文章推荐
- hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
- HDU 4543|三足鼎立|曼哈顿距离|二分答案
- HDU 4311 Meeting point-1(曼哈顿距离最小)
- HDU-4666 Hyperspace 曼哈顿距离
- Hdu 4312-Meeting point-2 切比雪夫距离,曼哈顿距离,前缀和
- HDU 4311&2 Meeting point-1&2(曼哈顿距离&&切比雪夫距离)
- HDU 4311&4312 Meeting point-1&2 (曼哈顿距离&&切比雪夫距离)
- HDU 4311 Meeting point-1(曼哈顿距离优化枚举)
- HDU 4666 Hyperspace(最长曼哈顿距离)
- HDU 4312 最小切比雪夫距离-转化成曼哈顿距离再分治
- hdu-4666-Hyperspace-最长曼哈顿距离
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- HDU-4311 Meeting point-1 曼哈顿距离快速计算
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- HDU 4312 Meeting point-2(切比雪夫距离转曼哈顿距离)
- hdu 5762 Teacher Bo 曼哈顿路径
- HDU 4311,4312 Meeting point(曼哈顿距离,切比雪夫距离)
- HDU 4666 最远曼哈顿距离
- hdu 4666 (经典求曼哈顿距离 + multiset容器)
- HDU 4666 STL求多维最远曼哈顿距离