BZOJ2618[CQOI2006] convex polygon half-plane intersection

Source: Internet
Author: User

This is a half-plane of the naked problem, the first half-plane to write, just say I half-plane cross understanding it.

The so-called half-plane intersection, is to find a large pile of two of yuan an inequality of the intersections, and each two yuan of the solution set of an inequality can be seen in a straight line above or below the standard equation of the contact line can be obtained. So these inequalities can be converted to some half-plane, which is half-plane intersection.

The semi-planar intersection is impossible to hand over the concave polygon (because the definition of a concave polygon is that a straight line with an edge can divide the polygon into several blocks ...). yy a bit know this is not possible), this is a very beautiful nature, is similar to convex hull (the wording is somewhat similar), but the semi-plane may hand over the unbounded, so you can add four similar to a box of a straight line to the box up, you can avoid the appearance of the unbounded situation, of course, may surrender the solution, A point or a straight line (two points), a sentence is good.

There is a very violent n^2 practice, that is, each time you add a line, violence to the intersection with the current line, and then determine which parts are not feasible, which parts are possible ... (Very violent, and very difficult to write ....) )

There are also two (probably three ... But the latter two ideas are similar) Nlogn practice, one is the division, the current half-plane number of divided treatment, recursive return to find, and then use scan line sweep past .... But the constants are large and difficult to write.

Another NLOGN approach is to maintain a monotonic stack, with a convex shell and a lower convex shell, if the line stack[top] and the current straight line a[i] intersections are top--outside the current half-plane, and then combine the resulting convex hull and a lower convex hull

But the merger is still a bit of trouble, you can use a two-way queue to maintain a convex hull, each time adding a straight line to the team head and tail and then add to the end of the team, but the specific implementation process may be problematic, because the angle is increased (all as counterclockwise rotation, so convenient), So the polar angle of the current line must be larger than the polar angle of all the lines in the queue, so there must be a contribution to the answer (that is, it will be the boundary, in the case of not being sentenced by the following straight line), in the maintenance of the two monotone stack is not considered (as if the merger should be considered), but deque Therefore, the slope of the final line is large, but does not necessarily contribute to the half-plane (after all, it is queue[++tail]=a[i]), so it will need two times while the head of the team or something. This is very convenient and the core code is huge ....

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 #defineMAXN 20008 #defineEPS 1e-09   Ten intn,m,tot,cnt; One    A structpoint{ -     Doublex, y; - }P[MAXN],PT[MAXN]; the    - structline{ -Point from, to; -     Doubleslope; + }L[MAXN],Q[MAXN]; -    +Pointoperator-(point A,point b) {return(point) {a.x-b.x,a.y-b.y};} APointoperator+ (point A,point b) {return(point) {a.x+b.x,a.y+b.y};} at Double operator* (Point A,point b) {returna.x*b.y-a.y*b.x;} - BOOL operator<(line A,line b) { -     return(A.slope==b.slope)? (A.to-a. from) * (B.to-a. from) <0):a.slope<B.slope; - } - BOOL operator==(line A,line b) { -     returna.slope==B.slope; in } -    to Point GetPoint (line A,line b) { +     DoubleT1= (B.to-a. from) * (A.to-a. from), t2= (A.to-a. from) * (b. from-A. from); -     DoubleT=T1/(t1+T2); the     return(point) {(b. from. x-b.to.x) *t+b.to.x, (b. from. y-b.to.y) *t+B.TO.Y}; * } $   Panax Notoginseng BOOLCheck (line a,line b,line c) { -Point d=GetPoint (A, b); the     return(C.to-c. from) * (d-c. from) <0; + } A    the voidsolve () { +     intHead=1, tail=2; -q[1]=l[1],q[2]=l[2]; $      for(intI=3; i<=n;i++){ $          while(Head<tail && Check (q[tail-1],q[tail],l[i]) tail--; -          while(Head<tail && Check (q[head+1],q[head],l[i]) head++; -q[++tail]=L[i]; the     } -      while(Head<tail && Check (q[tail-1],q[tail],q[head]) tail--;Wuyi      while(Head<tail && Check (q[head+1],q[head],q[tail]) head++; theq[tail+1]=q[head],cnt=0; -      for(inti=head;i<=tail;i++) Pt[++cnt]=getpoint (q[i],q[i+1]); Wu } -    About intMain () { $scanf"%d",&n); -      for(intI=1; i<=n;i++){ -scanf"%d",&m); -          for(intj=1; j<=m;j++) scanf ("%LF%LF",&p[j].x,&p[j].y); Ap[m+1]=p[1]; +          for(intj=1; j<=m;j++) L[++tot]. from=p[j],l[tot].to=p[j+1]; the     } -      for(intI=1; i<=tot;i++) l[i].slope=atan2 (L[i].to.y-l[i]. from. Y,l[i].to.x-l[i]. from. x); $Sort (L +1, l+tot+1); then=0; theN=unique (L +1, l+tot+1)-l; then--; the solve (); -     Doubleans=0; in     if(cnt<=2){ theprintf"0.000"); the         return 0; About     } thept[++cnt]=pt[1]; the      for(intI=1; i<=cnt;i++) ans+=pt[i]*pt[i+1]; theprintf"%.3LF", ans/2); +     return 0; -}
View Code

BZOJ2618[CQOI2006] convex polygon half-plane intersection

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.