Test instructions
There are n blocks of non-overlapping rectangular planks, with the small convex polygon to wrap them up, and output and output the total area of the wood to occupy the percentage of the convex polygon area.
Analysis:
A bare question that is almost convex and polygon area.
Note: The final output of the percent semicolon preceded by a space, the first time to cross the PE.
Print% with printf, two%%,printf ("%%\n") can be printed continuously; This cold knowledge remember to learn before, but do not forget.
Learn the tips for weight-taking in vector containers.
Sort (P.begin (), P.end ());p. Erase (Unique (P.begin (), P.end ()), P.end ());
The Convexhull function finally uses resize (n), as the name implies, changing the size of the container to N. An element that exceeds the range is invalid, and the next push_back element will be followed by the nth one.
1 //#define LOCAL2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6#include <vector>7 using namespacestd;8 9 Const DoublePI = ACOs (-1.0);Ten One struct Point A { - Doublex, y; -Point (Doublex=0,Doubley=0): X (x), Y (y) {} the }; - typedef point Vector; -Pointoperator+ (vector A, vector B) {returnVector (a.x+b.x, a.y+b.y); } -Pointoperator-(vector A, vector B) {returnVector (a.x-b.x, a.y-b.y); } + DoubleCross (Constvector& A,Constvector& B) {returna.x*b.y-a.y*b.x;} -Vector Rotate (vector A,Doublep) + { A returnVector (A.x*cos (P)-a.y*sin (p), A.x*sin (p) +a.y*cos (p)); at } - BOOL operator< (Constpoint& A,Constpoint&B) - { - returna.x < b.x | | (a.x = = b.x && A.y <b.y); - } - BOOL operator== (Constvector& A,Constvector&B) in { - returna.x = = b.x && A.y = =b.y; to } + - DoubleTorad (Doublex) {returnX/180.0*PI;} the *Vector<point> Convexhull (vector<point>p) $ {Panax Notoginseng //Ô¤´¦àí£¬è¥öø - sort (P.begin (), P.end ()); the p.erase (Unique (P.begin (), P.end ()), P.end ()); + A intn =p.size (); the intm =0; +Vector<point> CH (n+1); - for(inti =0; I < n; ++i) $ { $ while(M >1&& Cross (ch[m-1]-ch[m-2], p[i]-ch[m-2]) <=0) m--; -ch[m++] =P[i]; - } the intK =m; - for(inti = n2; I >=0; --i)Wuyi { the while(M > K && Cross (ch[m-1]-ch[m-2], p[i]-ch[m-2]) <=0) m--; -ch[m++] =P[i]; Wu } - if(N >1) m--; About ch.resize (m); $ returnch; - } - - DoublePolygonarea (vector<point>p) A { + intn =p.size (); the DoubleAns =0.0; - for(inti =0; I < n1; ++i) $Ans + = Cross (p[i]-p[0], p[i+1]-p[0]); the returnans/2; the } the the intMainvoid) - { in #ifdef LOCAL theFreopen ("10652in.txt","R", stdin); the #endif About the intT; thescanf"%d", &T); the while(t--) + { - intN; theVector<point>p;Bayi DoubleAREA1 =0.0; thescanf"%d", &n); the for(inti =0; I < n; ++i) - { - Doublex, Y, W, H, A; thescanf"%LF%LF%LF%LF%LF", &x, &y, &w, &h, &a); the Point O (x, y); the DoubleAng =-Torad (a); theP.push_back (o + Rotate (Vector (w/2, h/2) , ANG); -P.push_back (o + Rotate (Vector (-w/2, h/2) , ANG); theP.push_back (o + Rotate (Vector (w/2,-h/2) , ANG); theP.push_back (o + Rotate (Vector (-w/2,-h/2) , ANG); theArea1 + = w*h;94 } the DoubleAREA2 =Polygonarea (Convexhull (P)); theprintf"%.1LF%%\n", AREA1/AREA2 *100.0); the }98}
code June
UVa 10652 (Simple convex bag) Board wrapping