HDU 5762 [简单复杂度分析]

Description

给定 n 个点,求是否存在两对点曼哈顿距离相等。
0xi,yi105

Solution

曼哈顿距离的个数应该也是 O(n) 的啦。。。

#include <bits/stdc++.h>
using namespace std;

const int N = 201010;

inline char get(void) {
    static char buf[100000], *S = buf, *T = buf;
    if (S == T) {
        T = (S = buf) + fread(buf, 1, 100000, stdin);
        if (S == T) return EOF;
    }
    return *S++;
}
inline void read(int &x) {
    static char c; x = 0;
    for (c = get(); c < '0' || c > '9'; c = get());
    for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
}

int test, n, m, d, ans;
struct Point {
    int x, y;
    Point (int _x = 0, int _y = 0):x(_x), y(_y) {}
};
Point a[N];
int vis[N];

inline int Dis(Point &a, Point &b) {
    return fabs(a.x - b.x) + fabs(a.y - b.y);
}

int main(void) {
    freopen("1.in", "r", stdin);
    read(test);
    for (int t = 1; t <= test; t++) {
        read(n); read(m); ans = 0;
        for (int i = 1; i <= n; i++) {
            read(a[i].x); read(a[i].y);
        }
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                d = Dis(a[i], a[j]);
                if (vis[d] == t) {
                    ans = 1; break;
                }
                vis[d] = t;
            }
            if (ans) break;
        }
        puts(ans ? "YES" : "NO");
    }
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值