Teacher Bo (时间复杂度 + 暴力)

如果你仔细看就会发现有一个数据很重要那就是点的范围,那么这样一来最多只有2 * maxn的不同曼哈顿距离了,这样一看只要暴力一下就可以过了。

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

const int maxn = 1e5 + 7;
int x[maxn], y[maxn];
bool cn[maxn * 2];

int cnt(int a, int b){
    return abs(x[a] - x[b]) + abs(y[a] - y[b]);
}

bool solve(int n, int m){
    if(n * (n - 1) > 2 * maxn) return true;
    memset(cn, false, sizeof(cn));
    for(int i = 0; i < n; i ++)
        for(int j = i + 1; j < n; j ++)
            if(cn[cnt(i, j)]) return true;
            else cn[cnt(i, j)] = true;
    return false;
}

int main(){
    int T, n, m;scanf("%d", &T);
    while(T -- ){
        scanf("%d%d", &n, &m);
        for(int i = 0; i < n; i ++)scanf("%d%d", &x[i], &y[i]);
        printf("%s
", solve(n, m)?"YES":"NO");
    }
    return 0;
}
more crazy more get!
原文地址:https://www.cnblogs.com/wethura/p/9823799.html