[APIO2018] Select Circle (kd-tree)

Source: Internet
Author: User
Tags cos sin

Test instructions: give you n a circle, each time you select the largest radius, it and the circle that intersects it all deleted, the output of each circle is deleted at which time.

kd Tree template problem. Use a rectangular frame to hold the circle, and you can prune it directly. In order to prevent the card can rotate the point of an angle, in order to insure can also turn several angles.

1#include <cmath>2#include <cstdio>3#include <algorithm>4 #defineRep (i,l,r) for (int i= (l); i<= (R); i++)5typedefDoubledb;6 using namespacestd;7 8 Const intn=300010;9 ConstDB inf=1e20,eps=1e-3, Alpha=acos (-1)/3;Ten intN,rt,ans[n]; One db x,y,r; A structp{DB x,y,r;intID;} Cur,a[n]; - structtr{intls,rs; DB x1,y1,x2,y2; P C; }t[n]; -  the BOOLCMPX (ConstP &a,ConstP &b) {returna.x<b.x;} - BOOLCmpy (ConstP &a,ConstP &b) {returna.y<b.y;} - BOOLCMPR (ConstP &a,ConstP &b) {return(A.R==B.R)? A.id<b.id:a.r>B.R;} -  + voidFintXinty) { -T[x].x1=min (T[X].X1,T[Y].X1); T[x].x2=Max (t[x].x2,t[y].x2); +T[x].y1=min (T[X].Y1,T[Y].Y1); T[x].y2=Max (t[x].y2,t[y].y2); A } at  - voidUpdintx) { -     if(Ans[t[x].c.id]) t[x].x1=t[x].y1=inf,t[x].x2=t[x].y2=-inf; -     Else{ -T[X].X1=T[X].C.X-T[X].C.R; t[x].x2=t[x].c.x+T[X].C.R; -T[X].Y1=T[X].C.Y-T[X].C.R; t[x].y2=t[x].c.y+T[X].C.R; in     } -     if(T[X].LS) F (x,t[x].ls); to     if(t[x].rs) F (x,t[x].rs); + } -  the intBuildintLintRintk) { *     if(L>r)return 0; $     intMid= (l+r) >>1; Nth_element (a+l,a+mid,a+r+1K?cmpy:cmpx);Panax NotoginsengT[mid].c=A[mid]; -T[mid].ls=build (l,mid-1, k^1); T[mid].rs=build (mid+1, r,k^1); theUPD (mid);returnmid; + } A  theDB SQR (db x) {returnx*x;} + BOOLOut (intx) {return(t[x].x2<cur.x-cur.r-eps) | | (t[x].x1>cur.x+cur.r+eps) | | (t[x].y2<cur.y-cur.r-eps) | | (t[x].y1>cur.y+cur.r+EPS); } - BOOLCHK (P &a) {returnSqr (a.x-cur.x) +sqr (A.Y-CUR.Y) &LT;=SQR (A.R+CUR.R) +EPS;} $  $ voidQueintx) { -     if(Out (x))return; -     if(!ans[t[x].c.id] && chk (t[x].c)) ans[t[x].c.id]=cur.id; the     if(t[x].ls) que (t[x].ls); -     if(t[x].rs) que (t[x].rs);Wuyi } the  - intMain () { WuFreopen ("apiob.in","R", stdin); -Freopen ("Apiob.out","W", stdout); Aboutscanf"%d",&n); $Rep (I,1, N) -scanf"%LF%LF%LF", &x,&y,&r), a[i]= (P) {X*cos (alpha) +y*sin (Alpha), Y*cos (Alpha)-x*sin (alpha), r,i}; -Rt=build (1N0); Sort (A +1, a+n+1, CMPR); -Rep (I,1, N)if(!ans[a[i].id]) ans[a[i].id]=a[i].id,cur=A[i],que (RT); ARep (I,1, N) printf ("%d", Ans[i]); Puts""); +     return 0; the}

[APIO2018] Select Circle (kd-tree)

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.