Polygon Convex package ....
Board Wrapping
Time Limit: 3000MS |
Memory Limit: Unknown |
64bit IO Format: %lld &%llu |
Submit Status Description 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. InputOn 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. OutputFor 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 givenpicture Source Root:: Competitive programming 3:the New Lower Bound of programming contests (Steven & Felix Halim):: (Computationa L) Geometry:: Polygon:: Standard Root:: AOAPC i:beginning Algorithm Contests--Training Guide (Rujia Liu):: Chapter 4. Geometry:: Geometric Algorithms in 2D:: Examples
Root:: Competitive programming 2:this increases the lower bound of programming contests. Again (Steven & Felix Halim):: (Computational) Geometry:: Polygon-standardSubmit Status |
|
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath> #include <vector>using namespace Std;const double eps=1e-6;int dcmp (double x) {if (Fabs (x) <eps) return 0; Return (x<0)? -1:1;} struct point{double x, y; Point () {} point (double _x,double _y): X (_x), Y (_y) {};}; Point operator+ (Point A,point B) {return point (A.X+B.X,A.Y+B.Y);} Point operator-(Point A,point B) {return point (A.X-B.X,A.Y-B.Y);} Point operator* (Point a,double p) {return point (a.x*p,a.y*p);} Point operator/(Point a,double p) {return point (a.x/p,a.y/p);} BOOL operator< (const point& a,const point& B) {return dcmp (a.x-b.x) <0| | (DCMP (a.x-b.x) ==0&&dcmp (A.Y-B.Y) <0);} BOOL operator== (const point& a,const point& b) {return dcmp (a.x-b.x) ==0&&dcmp (A.Y-B.Y) ==0;} Double Angle (Point v) {return atan2 (v.y,v.x);} Point Rotate (Point a,double rad) {return point (A.x*cos (RAD)-a.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD));} Double Torad (DoubLe deg) {return Deg/180.*acos ( -1.);} Double Cross (point A,point B) {return a.x*b.y-a.y*b.x;} int n;double area0,area1;vector<point> vp,ch;//point Set convex bag//If you do not want to have an input point on the side of the convex hull, change the two <= to <//Note: The input point assembly is modified vector< Point> covexhull (vector<point>& p) {sort (P.begin (), P.end ()); P.erase (Unique (P.begin (), P.end ()), P.end ()); int n=p.size (); int m=0; vector<point> CH (n+1); for (int i=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]; } int k=m; for (int i=n-2;i>=0;i--) {while (M>k&&cross (Ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--; Ch[m++]=p[i]; } if (n>1) m--; Ch.resize (m); return ch;} Double Polygonarea (vector<point>& p) {int n=p.size (); Double area=0; for (int i=1;i<n-1;i++) Area+=cross (p[i]-p[0],p[i+1]-p[0]); Return AREA/2.;} int main () {int t_t; scanf ("%d", &t_t); while (t_t--) {scanf ("%d", &n); area0=area1=0.0; Vp.clear (); DouBLE x,y,w,h,j; for (int i=0;i<n;i++) {scanf ("%lf%lf%lf%lf%lf", &x,&y,&w,&h,&j); Area0+=w*h; Double Rad=torad (j); Point O (x, y); Vp.push_back (O+rotate (Point (W/2,H/2),-rad)); Vp.push_back (O+rotate (Point (-W/2,H/2),-rad)); Vp.push_back (O+rotate (Point (W/2,-H/2),-rad)); Vp.push_back (O+rotate (Point (-W/2,-H/2),-rad)); } ch=covexhull (VP); Area1=polygonarea (CH); printf ("%.1lf%%\n", 100.*area0/area1); } return 0;}
UVA 10652 Board Wrapping Computational Geometry