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

时间:2022-02-28 19:22:04

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

#include<bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
int x[maxn], y[maxn];
bool cn[maxn * ]; 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 - ) > * maxn) return true;
memset(cn, false, sizeof(cn));
for(int i = ; i < n; i ++)
for(int j = i + ; 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 = ; i < n; i ++)scanf("%d%d", &x[i], &y[i]);
printf("%s\n", solve(n, m)?"YES":"NO");
}
return ;
}