——————————————————————————题解
路径的长度是1-200000
然后路径的条数有n*(n+1)/2
根据鸽巢原理n*(n+1)/2 > 200000就一定是YES
所以复杂度只有n^2
1 #include <iostream> 2 #include <queue> 3 #include <set> 4 #include <cstdio> 5 #include <cstring> 6 #include <vector> 7 #include <algorithm> 8 #include <cmath> 9 #define siji(i,x,y) for(int i=x;i<=y;++i) 10 #define gongzi(j,x,y) for(int j=x;j>=y;--j) 11 #define xiaosiji(i,x,y) for(int i=x;i<y;++i) 12 #define sigongzi(j,x,y) for(int j=x;j>y;--j) 13 #define ivorysi 14 #define inf 0x3f3f3f3f 15 #define mo 97797977 16 #define ha 974711 17 #define ba 47 18 #define fi first 19 #define se second 20 #define pii pair<int,int> 21 typedef long long ll; 22 using namespace std; 23 int T,n,m; 24 int x[100005],y[100005]; 25 bool check[200005],flag; 26 int dist(int a,int b) { 27 return abs(x[a]-x[b])+abs(y[a]-y[b]); 28 } 29 void init() { 30 scanf("%d%d",&n,&m); 31 siji(i,1,n) { 32 scanf("%d%d",&x[i],&y[i]); 33 } 34 flag=0; 35 memset(check,0,sizeof(check)); 36 } 37 void solve() { 38 scanf("%d",&T); 39 while(T--){ 40 init(); 41 if(n>=30000) puts("YES"); 42 siji(i,1,n) { 43 siji(j,i+1,n) { 44 int x=dist(i,j); 45 if(check[x]) {flag=1;goto suc;} 46 else check[x]=1; 47 } 48 } 49 suc: 50 if(flag) puts("YES"); 51 else puts("N0"); 52 } 53 } 54 int main(int argc, char const *argv[]) 55 { 56 #ifdef ivorysi 57 freopen("island.in","r",stdin); 58 freopen("island.out","w",stdout); 59 #else 60 freopen("f1.in","r",stdin); 61 #endif 62 solve(); 63 return 0; 64 }
时间: 2024-10-20 23:04:49