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<B,C<D,A≠CorB≠D)的意思是两线段不能同时共两端点.


题解:


这个题让我懵比的两个小时...
一开始先把曼哈顿距离想成了abs(dx+dy),然后可以只考虑每个点的坐标和,从而误把题目转化为求一个数组中是否有两对数的和相等.
由于规模是1e5,然后一直在想O(nlogn)的算法...


首先,曼哈顿距离的正确定义是abs(dx)+abs(dy).
其次,题目的数据规模确实不能跑O(n^2)的算法,但是题目限制了坐标的范围为[0,1e5], 这意味着任意两点的曼哈顿距离只可能有2e5种可能,暴力最多只会判断2e5个组合,所以不会超时.
所以直接暴力判断所有组合即可,当出现重复的距离时停止判断(先离线数据).


这个题懵比这么久真的是非常不应该,所以以后卡题的时候,一定要重新读题和尝试转换思考角度.


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#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;
}

转载于:https://www.cnblogs.com/Sunshine-tcf/p/5709156.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值