HDU 5762 Teacher Bo (pigeon cage principle) 2016 Hangzhou Electric Multi-school joint third Field

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.