hdu 5762 Teacher Bo(鸽巢原理)
2016-07-26 20:28
357 查看
思路:虽然有10^5个点,可是两两曼哈顿距离不会超过2*10^5,所以根据鸽巢原理有复杂度为不会超过2*10^5
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const 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".
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
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const 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".
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
相关文章推荐
- linux基础学习-第三天记录
- Java 之 线程的生命周期(三)
- hdu5761Rower Bo+数学积分
- 201. Bitwise AND of Numbers Range
- visual studio 2015安装.net core 问题
- HDU 5761 Rower Bo
- 使用 CXF 做 webservice 简单例子
- Codeforces 439D Devu and his Brother
- JS数组实现队列和堆栈
- linux基础1
- 【CodeForces】371C - Hamburgers(二分)
- 单例模式深入学习
- Android Studio 导入第三方jar包
- c#之用StreamWriter追加写文件
- 重复元素的删除问题
- Failed to instantiate * using constructor public * with arguments **
- 【HDU 1950】Bridging signals(LIS算法求最长上升子序列)
- android ListView 记录当前位置 恢复
- 操蛋的Camera V2
- linux文件系统及文件属性