UVA 10652 Board Wrapping (convex bag)

Source: Internet
Author: User
Tags acos cos in degrees sin

The small sawmill in Mission, British Columbia, have
Developed a brand new to packaging boards for
Drying. By fixating the boards in special moulds, the
Board can dry efficiently in a drying.
Space is an issue though. The boards cannot be
Too close, because then the drying would be too slow.
On the other hand, one wants to use the drying
efficiently.
Looking at it from a 2-d perspective, your task is
To calculate the fraction between the space occupied by
The boards to the total space occupied by the mould.
Now, the mould are surrounded by an aluminium frame
of negligible thickness, following the hull of the Boards '
Corners tightly. The space occupied by the mould
Would thus be the interior of the frame.
Input
On the first line of input there is one integer, n≤50,
Giving the number of test cases (moulds) in the input. After this line, N test cases follow. Each test case
Starts with a line containing one integer n, 1 < n≤600, which are the number of boards in the mould.
Then n lines follow, each with five floating point numbers x, Y, W, H,? where 0≤x, Y, W, h≤10000
And−90? <? ≤90?
. The X and Y are the coordinates of the center of the board and W and H is the
Width and height of the board, respectively. ? The angle between the height axis of the board to the
Y-axis in degrees, positive clockwise. That's, if? = 0, the projection of the Board on the x-axis would
Be W. Of course, the boards cannot intersect.
Output
For every test case, output one line containing the fraction of the space occupied by the boards to the
Total space in percent. Your output should have one decimal digit and is followed by a space and a
Percent sign ('% ').
Note:the sample Input and sample Output corresponds to the given
Sample Input
1
4
4 7.5 6) 3 0
8 11.5 6) 3 0
9.5 6 6) 3 90
4.5 3 4.4721) 2.2361 26.565
Sample Output
64.3%

Solving: The ratio of the rectangular area to the convex hull area, clockwise must be negative .... The wrong day ... And the ANG to be converted to RAD.

Code:

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 Const DoublePi=acos (-1.0);8 structpoint{9     Doublex, y;TenPoint (Doublex=0,Doubley=0): X (x), Y (y) {} One }; A typedef point Vector; - BOOL operator< (point A,point b) {returna.x<b.x| | (a.x==b.x&&a.y<b.y);} -Vectoroperator-(point A,point b) {returnVector (a.x-b.x,a.y-b.y);} the DoubleDot (Vector A,vector b) {returna.x*b.x+a.y*b.y;} - DoubleLength (Vector a) {returnsqrt (Dot (a,a));} - DoubleAngle (Vector A,vector b) {returnACOs (Dot (b)/length (a)/Length (b)); -Vector Rotate (Vector A,Doublerad) {returnVector (A.x*cos (RAD)-a.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD));} + DoubleCross (Vector A,vector b) {returna.x*b.y-a.y*b.x;} -Pointoperator+ (point A,vector b) {returnPoint (a.x+b.x,a.y+b.y);} +Point Getdot (point A,vector B,DoubleANG) {returnA +Rotate (B,ang);} A DoubleGetrad (DoubleANG) {returnpi* (ang/ the);} atPoint ans[2500],at[2500]; - intNu; - DoublePolygonarea () { -     intk=0; -      for(intI=0; i<nu;i++){ -          while(k>1&&cross (ans[k-1]-ans[k-2],at[i]-ans[k-2]) <=0) k--; inans[k++]=At[i]; -     } to     intp=K; +      for(inti=nu-1; i>=0; i--){ -          while(K>p&&cross (ans[k-1]-ans[k-2],at[i]-ans[k-2]) <=0) k--; theans[k++]=At[i]; *     } $     Doublex=0;Panax Notoginsengk--; -     if(k<2)return 0; the      for(intI=1; i<k-1; i++) X+=cross (ans[i]-ans[0],ans[i+1]-ans[0]); +     returnx/2; A } the intMain () { +     intT,n; -     DoubleX,y,w,h,ang; $scanf"%d",&T); $      while(t--){ -         Doublearea1=0, area2=0; -nu=0; thescanf"%d",&n); -          while(n--){Wuyiscanf"%LF%LF%LF%LF%LF",&x,&y,&w,&h,&ang); thearea2+=w*h; - Point A; WuAng=-getrad (ANG);//because it is clockwise rotation, so if the negative ...  -At[nu++]=getdot (Point (x, y), Vector (w/2, h/2), ANG); AboutAt[nu++]=getdot (Point (x, y), Vector (-w/2, h/2), ANG); $At[nu++]=getdot (Point (x, y), Vector (w/2,-h/2), ANG); -At[nu++]=getdot (Point (x, y), Vector (-w/2,-h/2), ANG); -         } -Sort (at,at+nu); Aarea1=Polygonarea (); +     //printf ("%lf%lf\n", area1,area2); theprintf"%.1LF%%\n", -*area2/area1); -     } $     return 0; the}

UVA 10652 Board wrapping (convex bag)

Related Article

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.