Test instructions: To find the area on both sides of a straight-line split convex package.
Solution: Because test instructions will say must pass, then there will not be a straight line and a side coincident with the case. We just have to find a convex hull of a straight line, and the other area equals the total area minus that area.
How do you get a convex bag that is partitioned?
Sweep through the past, if the sweep of the edge and the line does not intersect, then put the endpoint into the new convex hull, if the line and sweep to the edge of the intersection, then the intersection of the new convex hull, and then do not intersect the point into the new convex package, until the next intersection with the line to meet the edge, the intersection is added to the Then join the point at the end of the sweep. That's the way it gets.
is found
Notice rounding.
Code:
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#defineEPS 1e-8using namespacestd;structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {}voidInput () {scanf ("%LF%LF",&x,&y); }};typedef point Vector;intDCMP (Doublex) {if(x <-eps)return-1; if(X > EPS)return 1; return 0;} Template<classT> T Sqr (t x) {returnX *x;} Vectoroperator+ (vector A, vector B) {returnVector (a.x + b.x, A.Y +b.y); }vectoroperator-(vector A, vector B) {returnVector (a.x-b.x, A.Y-b.y); }vectoroperator* (Vector A,DoubleP) {returnVector (A.x*p, a.y*p); }vectoroperator/(Vector A,DoubleP) {returnVector (a.x/p, a.y/Q); }BOOL operator< (Constpoint& A,Constpoint& b) {returna.x < b.x | | (a.x = = b.x && A.y <b.y); }BOOL operator>= (Constpoint& A,Constpoint& b) {returna.x >= b.x && a.y >=b.y;}BOOL operator<= (Constpoint& A,Constpoint& b) {returna.x <= b.x && a.y <=b.y;}BOOL operator== (Constpoint& A,Constpoint& b) {returnDCMP (a.x-b.x) = =0&& dcmp (a.y-b.y) = =0; }DoubleDot (vector A, vector B) {returna.x*b.x + a.y*b.y;}DoubleLength (Vector A) {returnsqrt (Dot (A, a));}DoubleCross (vector A, vector B) {returna.x*b.y-a.y*b.x;} Point DisP (Point A,point B) {returnLength (b-A); }BOOLsegmentintersection (Point a,point b,point c,point D) {returnMax (a.x,b.x) >= min (c.x,d.x) &&Max (c.x,d.x)>= min (a.x,b.x) &&Max (A.Y,B.Y)>= min (c.y,d.y) &&Max (C.Y,D.Y)>= min (a.y,b.y) &&dcmp (Cross (C-A,B-A) *cross (d-a,b-a)) <=0&&dcmp (Cross (A-C,D-C) *cross (b-c,d-c)) <=0;}voidSegintersectionpoint (point& p,point a,point b,point c,point d) {//AB,CD must be guaranteed to intersectp.x = (Cross (d-a,b-a) *c.x-cross (c-a,b-a) *d.x)/(Cross (d-a,b-a)-cross (c-a,b-a)); P.Y= (Cross (d-a,b-a) *c.y-cross (c-a,b-a) *d.y)/(Cross (d-a,b-a)-cross (c-a,b-a));}DoubleCalcconvexarea (point* p,intN) { DoubleArea =0.0; for(intI=1; i<n-1; i++) Area+ = Cross (p[i]-p[0],p[i+1]-p[0]); returnFabs (area*0.5);} Point p[ -],ch[ -]; Point P,a,b;intMain () {intn,i,m; while(SCANF ("%d", &n)!=eof &&N) { for(i=0; i<n;i++) P[i].input (); A.input (), B.input (); Point Tmpa= B + (a) *20003, TMPB = a + (b-a) *20003; A= Tmpa, B =TMPB; DoubleTotal =Calcconvexarea (p,n); inttot =0, fir =0, add =0; Ch[tot+ +] = p[0]; for(i=0; i<n;i++) {Point C= P[i], D = p[(i+1)%N]; if(Segmentintersection (a,b,c,d)) {segintersectionpoint (p,a,b,c,d); Ch[tot++] =P; if(!fir) Fir =1; ElseFIR =0, add =1; if(P = = D) i++; } Else if(!fir) ch[tot++] = p[(i+1)%N]; if(add) ch[tot++] = p[(i+1)%N]; } Doublenow =Calcconvexarea (Ch,tot); Doubleother = total-Now ; intN = (int) (now+0.5), O = (int) (other+0.5); if(O >N) Swap (n,o); printf ("%d%d\n", N,o); } return 0;}
View Code
UESTC area-convex bag