Hdu3511-prison break

Source: Internet
Author: User

Remember the first scan line algorithm in life ..... In fact, not strictly the first way ... The first time I met the one that hasn't been ...

Topic Links:

http://acm.hdu.edu.cn/showproblem.php?pid=3511

This question should be considered as the basic problem of the scanning line.

For each circle, enter and go out when the scan line, respectively, is x = C[I].X-C[I].R, x ' = c[i].x + c[i].r;

So for each scan line, for x ', we delete the circle in the collection, which is a good understanding.

For x, we add the circle to the collection so that we can just look up the first intersection point and the first intersection.

But the problem is that the intersection coordinates are changing as the scan lines move, but we notice that the relative position of the points is not changed (i.e. the top is still above, below)

So we can pull a set to maintain the intersection of the scan line ordinate, this does not need to save the specific ordinate value, because the relative position is unchanged, the structure of the tree is unchanged.

You only need to reload the less-than sign when you use INSERT.

If the scan line is not pointing up or down, then the circle depth = 1;

If the top and bottom two points belong to the same circle ID, then this round depth = depth[id]+1;

If the top and bottom two circles belong to a different circle Id1,id2, then the depth of the circle = Max (Depth[id1], Depth[id2]);

AC Code:

1#include <bits/stdc++.h>2 3 using namespacestd;4 Const intMAXN =50000+Ten;5 6typedefstructcircle{7   intID, x, y, R;8 9Circle (intID =0,intx =0,inty =0,intR =0 ){Ten      This->id =ID; One      This->x =x; A      This->y =y; -      This->r =R; -   } the }circle; -  - Circle C[MAXN]; -  +typedefstructpoint{ -   intid, ty; +  APoint (intID =0,intTy =0 ){ at      This->id =ID; -      This->ty =Ty; -   } - }point; -  - Set<Point>s; in  -typedefstructline{ to   intID, x, ty; +  -Line (intID =0,intx =0,intTy =0 ){ the      This->id =ID; *      This->x =x; $      This->ty =Ty;Panax Notoginseng   } -  the   BOOL operator< (Constline& l)Const{ +     if(x = =l.x) A       returnID <l.id; the     returnX <l.x; +   } - }line; $  $Line l[maxn<<1]; -  - intDEPTH[MAXN]; the  - intN, ans, xlog;Wuyi  the DoubleIntersector (Constpoint&p) { -   intID =p.id; Wu   DoubleR =1.0*C[ID].R; -  About   Doublex =1.0* (Xlog-c[id].x); $   Doubley = sqrt ((r*r-x*x)); -  -   if(P.ty = =1) -     return 1.0*c[id].y +y; A   Else +     return 1.0*C[ID].Y-y; the } -  $ BOOL operator< (Constpoint& P1,Constpoint&p2) { the   if(P1.id = =p2.id) the     returnP1.ty <P2.ty; the   returnIntersector (p1) <intersector (p2); the } -  in voidSolveintnn) { thememset (Depth,0,sizeof(depth)); the s.clear (); AboutAns =0; the  the    for(inti =0; i < nn; ++i) { the     intid = l[i].id, ty =L[i].ty; +Xlog =l[i].x; -     //cout << "ID:" << ID << "ty:" << ty << Endl; the Bayi     if(Ty = =1 ){ theS.erase (Point (ID,0)); theS.erase (Point (ID,1)); -}Else{ -S.insert (Point (ID,0)); the       Set<point>::iterator it1 = S.find (Point (ID,0)), it2; theIt2 =it1; theit2++; the  -       if(It1 = = S.begin () | | it2 = =S.end ()) { theDepth[id] =1; the         //cout << "ID:" << ID << "depth[id": "<< Depth[id] << Endl; the}Else{94it1--; the         if(It1->id = = it2->ID) { theDepth[id] = depth[it1->id]+1; the}Else{98Depth[id] = max (Depth[it1->id], depth[it2->id]); About         } -         //cout << "ID:" << ID << "depth[id": "<< Depth[id] << Endl;101       }102S.insert (Point (ID,1));103     }104Ans =Max (ans, depth[id]); the   }106 107printf"%d\n", ans);108 }109  the intMainvoid){111    while(SCANF ("%d", &n)! =EOF) { theMemset (c,0,sizeof(c));113memset (L,0,sizeof(l)); the  the      for(inti =0; I < n; ++i) { theC[i].id =i;117scanf"%d%d%d", &c[i].x, &AMP;C[I].Y, &C[I].R);118l[i*2] = line (i, C[I].X-C[I].R,0);119l[i*2+1] = line (i, C[I].X+C[I].R,1); -     }121     intnn = n *2;122Sort (L, L +nn);123 124 solve (NN); the   }126 127   return 0; - }129  the /*131 5 the 0 0133 0 0 1134 0 5 3135 3 0 2136 0 0137 6138 0 0139 0 0 1 $ 0 5 3141 0 5 2142 3 0 2143 0 0144 */
View Code

Hdu3511-prison break

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.