hdu 5762 Teacher Bo(鸽巢原理)
来源:互联网 发布:传智播客java课程 编辑:程序博客网 时间:2024/05/22 15:00
思路:虽然有10^5个点,可是两两曼哈顿距离不会超过2*10^5,所以根据鸽巢原理有复杂度为不会超过2*10^5
#include<bits/stdc++.h>using namespace std;#define LL long longconst int maxn = 1e5+7;struct point{ int x, y;}p[maxn];int vis[2*maxn];int Dist(point a,point b){ int dist = abs(a.x - b.x) + abs(a.y - b.y); return dist;}int main(){ int T; scanf("%d",&T); while (T--) { int n, m, flag = 0; memset(vis,0,sizeof(vis)); scanf("%d%d",&n,&m);for(int i = 0;i<n;i++)scanf("%d%d",&p[i].x,&p[i].y); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int d = Dist(p[i], p[j]); if (!vis[d]) vis[d] = 1; else{ flag = 1; break; } } } if (flag == 1) cout << "YES" << endl; else cout << "NO" << endl; }}
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".
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
Source
2016 Multi-University Training Contest 3
0 0
- [HDU 5762] Teacher Bo (鸽巢原理)
- hdu 5762 Teacher Bo(鸽巢原理)
- HDU 5762 Teacher Bo(鸽巢定理)
- hdu 5762 Teacher Bo
- HDU 5762 Teacher Bo
- HDU 5762 Teacher Bo
- HDU 5762 Teacher Bo
- HDU 5762 Teacher Bo 2016多校赛第三场 鸽巢原理
- HDU 5762 Teacher Bo (暴力)
- HDU 5762 Teacher Bo (特判后暴力)
- HDU 5762 Teacher Bo (水题)
- hdu 5762 Teacher Bo(暴力美学)
- HDU-5762-Teacher Bo-水题
- 【模拟】HDU 5762 Teacher Bo
- hdu 5762 Teacher Bo(vector的使用1)
- HDU 5762 Teacher Bo(暴力+思维)
- MULti 2016 Teacher Bo(hdu 5763)
- Teacher Bo HDU
- Android扫一扫
- 你对C语言的关键字,知多少
- HDU 5754 博弈(威佐夫博弈)
- [OS复习]操作系统综述2
- JS数组实现队列和堆栈
- hdu 5762 Teacher Bo(鸽巢原理)
- 递归-算法题解1
- 最短路算法spfa hdu 1863
- hdu 3605 Escape/poj 2584 T-Shirt Gumbo(二分图多重匹配)
- 链表的双指针使用
- [Python] 技术贴系列之——Django部署方案简介
- 何教授去雾算法C++实现(调试)
- 超详细JSTL标签 参考手册
- Linux常见知识