Title: Portal.
Test instructions: The plane hasNPoint and ask if there are four points (A,B,C,D)(A<B , C < D , A ≠ C o R B ≠ D) make ab The absolute value of the horizontal ordinate difference and equals The absolute value of the horizontal ordinate difference of the CD and , n<10^5 , the coordinates of the point m < Span id= "mathjax-span-28" class= "Mo" > < Span id= "mathjax-span-33" class= "Mo" > < Span id= "mathjax-span-38" class= "Mi" > < Span id= "mathjax-span-43" class= "Mi" > <10^5 .
The problem: The complexity of the surface is O (n^2) will time out, and in fact these coordinate difference absolute value and maximum is 2*10^5, so the complexity is not O (n^2), but o (min (n^2,m)) , this is the famous pigeon cage principle.
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespacestd;intAbsinti) {if(i<0)return-i; returni;}intCalintXintYintX1,inty1) { returnABS (X-X1) + ABS (yy1);}intMain () {intn,m,t,x[100005],y[100005]; BOOLa[200005]; scanf ("%d",&T); while(t--) {scanf ("%d%d",&n,&m); Memset (A,0,sizeof(a)); for(intI=0; i<n;i++) {scanf ("%d%d",&x[i],&Y[i]); } for(intI=0; i<n;i++) for(intj=i+1; j<n;j++) { intt=Cal (X[i],y[i],x[j],y[j]); if(A[t]) {puts ("YES"); GotoNEXT; } A[t]=true; } puts ("NO"); NEXT:; } return 0;}
HDU 5762 Teacher Bo (pigeon cage principle) 2016 Hangzhou Electric Multi-school joint third Field