Problem B
Board Wrapping
input: standard input
output: standard output
Time Limit: 2 seconds
The small sawmill in Mission, British Columbia, had developed a brand new-from-the-a-packaging for boards. By fixating the boards in special moulds, the board can dry efficiently in a drying.
Space is an issue though. The boards cannot is too close, because then the drying would be too slow. On the other hand, one wants to use the drying the efficiently.
Looking at it from a 2-d perspective, your task was to calculate the fraction between the space occupied by the Bo Ards 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 Tigh tly. The space occupied by the mould would thus is the interior of the frame.
Input
On the first line of input there is one integer,N <=, giving the number of test cases (moulds) in the input. After the line,NTest cases follow. Each test case starts with a line containing one integerN,1< N <=, which is the number of boards in the mould. ThenNLines follow, each with five floating point numbersx, Y, W, H, Jwhere0 <= x, y, W, H <=10000and–90°< J <=90°. Thexandyis the coordinates of the center of the Board andWandhis the width and height of the board, respectively.JThe angle between the height axis of the board to they-axis in degrees, positive clockwise. That is, ifj = 0The projection of the Board on thex-axis would beW. 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 per cent. Your output should has one decimal digit and is followed by a space and a percent sign (%).
Sample input Output for 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 |
64.3%
|
Swedish National Contest
The sample Input and sample Output corresponds to the given picture
Main topic:
To the n rectangular planks, you need to wrap them up with a convex polygon that is as small as possible, and ask for a percentage of the total packing area.
Problem Solving Ideas:
The most important thing is to ask for convex package.
Problem Solving Code:
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm>using namespace std; Const double Eps=1e-7;struct point{double x, y; Point (double x0=0,double y0=0) {x=x0,y=y0; } void Read () {scanf ("%lf%lf", &x,&y);} friend bool operator < (point A,point b) {if (A.Y!=B.Y) return a.y<b.y; else return a.x<b.x; } double Getdis (point q) {return sqrt ((x-q.x) * (x-q.x) + (Y-Q.Y) * (Y-Q.Y));}; typedef point Vector; Vector operator + (vector a,vector B) {return vector (A.X+B.X,A.Y+B.Y);} Vector operator-(vector a,vector B) {return vector (A.X-B.X,A.Y-B.Y);} Vector operator * (vector a,double p) {return vector (a.x*p,a.y*p);} Vector operator/(vector a,double p) {return vector (a.x/p,a.y/p);} int dcmp (double x) {if (Fabs (x) <eps) return 0; else return x<0?-1:1;} Double Dot (Vector a,vector B) {return a.x*b.x+a.y*b.y;} Double Length (Vector A) {return sqrt (Dot (a,a));} Double Angle (Vector a,vector B) {return ACOs (Dot (A)/length (A)/length (B)); }double Cross (Vector a,vector B) {return a.x*b.y-a.y*b.x;} Vector Rotate (vector a,double rad) {return vector (A.x*cos (RAD)-a.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD));} Counterclockwise rotation rad angle double Torad (double ang) {return Ang/180.0*acos (-1.0);} const int maxn=2500; Point P[maxn];int n,top;double sum;bool cmp (point A,point B) {if (Fabs (a-p[0],b-a)) <eps) return A.getdis (p[ 0]) <b.getdis (p[0]); else return Cross (a-p[0],b-a) >0;} Double Convexhull () {top=1; Sort (p,p+n); Sort (p+1,p+n,cmp); for (int i=2;i<n;i++) {When (Top>0 && Cross (p[top]-p[top-1],p[i]-p[top-1)) <=0) top--; P[++top]=p[i]; } P[++top]=p[0]; Double area=0; for (int i=1;i<top;i++) {Area+=cross (p[i]-p[0],p[i+1]-p[0]); } return area/2.0;} void input () {n=0; sum=0; int m; scanf ("%d", &m); for (int. i=0;i<m;i++) {point O; Double W,h,ang,rad; scanf ("%lf%lf%lf%lf%lf", &o.x,&o.y,&w,&h,&ang); Rad=-torad (ANG); P[n++]=o+rotate (Vector (-w/2.0,-h/2.0), RAD); P[n++]=o+rotate (Vector (-w/2.0,h/2.0), RAD); P[n++]=o+rotate (Vector (w/2.0,h/2.0), RAD); P[n++]=o+rotate (Vector (w/2.0,-h/2.0), RAD); Sum+=w*h; }}void solve () {double ans=convexhull (); printf ("%.1lf%%\n", Sum*100.0/ans);} int main () {int T; scanf ("%d", &t); while (t-->0) {input (); Solve (); } return 0;}