bzoj:1941: [Sdoi2010]hide and Seek

Source: Internet
Author: User

1941: [Sdoi2010]hide and Seek time limit:16 Sec Memory limit:162 MB
submit:531 solved:295
[Submit] [Status] [Discuss] Description

Piglet Ipig in PKU just finished bored pig sex algebra class, talent intelligent Ipig was this door to his very simple class made very lonely, in order to eliminate loneliness, he decided to play with his good friend Gipi (chicken skin) A more lonely game---hide and seek. But, they feel, play ordinary hide and seek no meaning, or is not lonely enough, so they decided to play the lonely and incomparable crab version of hide and Seek, as the name implies, that is, they play the game only along the horizontal or vertical direction. After a lonely pair of scissors and stone cloth, they decided to Ipig to catch Gipi. Because they are very familiar with the terrain of PKU, so Gipi will only hide in the PKU within the N secret location, obviously Ipig will only in that N locations to find Gipi. At the beginning of the game, they selected a location, Ipig remained motionless, and then Gipi fled the scene for 30 seconds (obviously, Gipi would not stay in place). Then Ipig will randomly go to find gipi until it is found. Because Ipig is very lazy, so he always take the shortest path, moreover, he chose the starting point is not random, he wanted to find a location, so that the location to the farthest point and the nearest location of the least distance difference. Ipig now wants to know what the minimum distance difference is. Because Ipig now has no computer on hand, so it can't be programmed to solve such a simple problem, so he immediately called and asked you to help him solve the problem. Ipig tells you the coordinates of PKU's n secret locations, and asks you to program Ipig problems.

Input

The first line enters an integer N 2~n+1 line, two integers per line x, y, representing the coordinates of the I-place

Output

An integer that is the minimum value for the distance difference.

Sample Input4
0 0
1 0
0 1
1 1
Sample Output1
Poof, this is not the k-d tree template, it seems that did not write ... So I knocked, knocked, knocked and knocked. 233 ... Tle+wa then I started the film Yellow Seniors Code ... It's like the same. So I started to tune ... The algorithms that have never been written have a lot of problems with the details ... A day of adjustment ... A ... There is no use ...
#include <cstdio>#include<algorithm>using namespacestd;intn,m,nu,ans=1e9,ma,mi,ka,ki,x,ro,xx;structtr{intx, y; FriendBOOL operator<(tr a,tr b) {ifXreturna.x<b.x;Else returna.y<b.y; }};structtree{intXa,xi,ya,yi,ye,l,r; Tree () {L=r=xa=ya=ye=0; Xi=yi=1e9; }};TR a[500011];tree t[500011];CharCs;inlineintRead () {CS=getchar (); xx=0;  while(cs<'0'|| Cs>'9') cs=GetChar ();  while(cs>='0'&&cs<='9') xx=xx*Ten+cs- -, cs=GetChar (); returnxx;} InlineBOOLcmx (tr x,tr y) {returnx.x<y.x;} InlineBOOLcmy (tr x,tr y) {returnx.y<y.y;} InlineintMaxintXintY) {returnX>y?x:y;} InlineintMinintXintY) {returnX<y?x:y;} InlineintAbsintx) {returnx<0?-x:x;} InlineintJlintXinty) {    returnABS (a[x].x-a[y].x) +abs (a[x].y-a[y].y);} InlineintBuildintLintRintNow ) {X=Now ; intMid= (l+r) >>1; T[mid].ye=1; Nth_element (A+l,a+mid,a+r+1); T[mid].xa=t[mid].xi=a[mid].x; T[mid].ya=t[mid].yi=a[mid].y; if(L<mid) T[mid].l=build (l,mid-1, now^1), T[mid].xa=Max (T[T[MID].L].XA,T[MID].XA), T[mid].xi=min (t[t[mid].l].xi,t[mid].xi), T[mid].ya=Max (T[t[mid].l].ya,t[mid].ya), T[mid].yi=min (t[t[mid].l].yi,t[mid].yi); if(mid<r) T[mid].r=build (mid+1, r,now^1), T[mid].xa=Max (T[T[MID].R].XA,T[MID].XA), T[mid].xi=min (t[t[mid].r].xi,t[mid].xi), T[mid].ya=Max (T[t[mid].r].ya,t[mid].ya), T[mid].yi=min (t[t[mid].r].yi,t[mid].yi); returnMid;} InlineintgmintIintj) {returnMax (ABS (t[j].xa-a[i].x), ABS (t[j].xi-a[i].x)) +max (ABS (T[J].YA-A[I].Y), ABS (t[j].yi-a[i].y));} InlineintgnintIintj) {returnMax (A[i].x-t[j].xa,0) +max (-A[I].X+T[J].XI,0) +max (A[i].y-t[j].ya,0) +max (-a[i].y+t[j].yi,0);} InlinevoidQaintIintx) {    if(x!=i) Ma=max (MA,JL (i,x)), ka++; intdl=-1, dr=-1; if(T[X].L) dl=GM (I,T[X].L); if(T[X].R) dr=GM (I,T[X].R); if(dl>DR) {        if(dl>Ma) QA (I,T[X].L); if(dr>Ma) QA (I,T[X].R); }Else{        if(dr>Ma) QA (I,T[X].R); if(dl>Ma) QA (I,T[X].L); }}inlinevoidQiintIintx) {    if(x!=i) Mi=min (MI,JL (i,x)), ki++; intDl=1e9,dr=1e9; if(T[X].L) dl=gn (I,T[X].L); if(T[X].R) dr=gn (I,T[X].R); if(dl>DR) {        if(dr<mi) qi (I,T[X].R); if(dl<mi) qi (I,T[X].L); }Else{        if(dl<mi) qi (I,T[X].L); if(dr<mi) qi (I,T[X].R); }}intMain () {n=read (); Registerinti;  for(i=1; i<=n;i++) A[i].x=read (), a[i].y=read (); Ro=build (1N0);  for(i=1; i<=n;i++) {Ma=0; mi=1e9;        QA (I,ro); Qi (i,ro); if(Ma-mi<ans) ans=ma-mi; } printf ("%d\n", ans);}

bzoj:1941: [Sdoi2010]hide and Seek

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.