Uva 10652 Board Wrapping

Source: Internet
Author: User

Two times Unicom gate: Virtual Judge Uva 10652 Board Wrapping

/*Uva 10652 Board wrapping compute geometry to split each furniture into 4 points for all points to find a convex hull and then the area of convex hull can not be difficult to train. But there are a lot of 1 things to be aware of when it's good to be troublesome. The angle system turns to Radian System 2. Selection of EPS 3. The value of pi (just in case after all write ACOs (-1) ... ) 4. The details of breaking the furniture into four points 4. Calculate the area of a polygon*/#include<algorithm>#include<iostream>#include<cstdio>#include<cmath>#defineMax 2500#definePI 3.1415926535897#defineEPS 1e-8voidRead (int&Now ) {RegisterCharWord =GetChar ();  for(now =0;!isdigit (word); Word =GetChar ());  for(; isdigit (word); now = now *Ten+ Word-'0', Word =GetChar ());}structpoint{Doublex, y; Point (Const Double&__x,Const Double&__y): X (__x), Y (__y) {} point () {}BOOL operator< (ConstPoint &now)Const    {        return  This->x = = now.x? This->y < now.y: This->x <now.x; }        BOOL operator== (ConstPoint &now)Const    {        return( This->x-now.x < EPS) && ( This->y-now.y <EPS); }};typedef Point Vector; Vectoroperator+ (ConstVector &a,ConstVector &B) {    returnVector (a.x + b.x, A.Y +b.y);} Vectoroperator- (ConstVector &a,ConstVector &B) {    returnVector (a.x-b.x, A.Y-b.y);} Vectoroperator* (ConstVector &now,Const DoubleP) {    returnVector (now.x * P, NOW.Y *P);} Vectoroperator/ (ConstVector &now,Const DoubleP) {    returnVector (now.x/p, NOW.Y/P);} InlineDoubleTo_rad (DoubleNow ) {    returnNow/ the*PI;} Inline vector Rotate (vector A,Doublerad) {    returnVector (a.x * cos (RAD)-A.y * sin (rad), a.x * sin (rad) + A.y *cos (RAD));} InlineDoubleCross (vector A, vector B) {returna.x * B.Y-A.Y *b.x;}intConvex_hull (Point *point,intN, point *Stack) {std:: sort (point, Point+N); inttop =0;  for(inti =0; i < N; i + +)    {         for(Top >1&& Cross (Stack[top-1]-Stack[top-2], Point[i]-stack[top-2]) <=0; --top); Stack[top++] =Point[i]; }        intK =top;  for(inti = N-2; I >=0; --i) { for(Top > K && Cross (Stack[top-1]-Stack[top-2], Point[i]-stack[top-2]) <=0; --top); Stack[top++] =Point[i]; }    if(N >1)        --top; returntop; }DoublePolygon_area (Point *point,intN) {    DoubleArea =0;  for(inti =1; I < N-1; i + +) Area+ = Cross (Point[i]-point[0], Point[i +1]-point[0]); returnArea/2;} Point Point[max], Stack[max];intMain (intargcChar*argv[]) {    intT, N, M;    Read (T); Registerinti; Doublex, Y, W, H, J; Doubleangle, _area; intcur;  for(; T --T) {read (N); Cur=0, _area =0;  for(i =1; I <= N; ++i) {scanf ("%LF%LF%LF%LF%LF", &x, &y, &w, &h, &j);                    Point now (x, y); Angle= -To_rad (j); Point[cur+ +] = now + Rotate (Vector (-w/2,-H/2), angle); Point[cur+ +] = now + Rotate (Vector (w/2,-H/2), angle); Point[cur+ +] = now + Rotate (Vector (-w/2, H/2), angle); Point[cur+ +] = now + Rotate (Vector (w/2, H/2), angle); _area+ = W *h; } M=convex_hull (point, cur, Stack); Double__area =Polygon_area (Stack, M); printf ("%.1LF%%\n", _area * -/__area); }    return 0;}

Uva 10652 Board Wrapping

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.