Topic Portal
Test instructions: Tell a few rectangles about the area they occupy in a convex polygon
Analysis: Training guide P272, rectangular area long * wide, as long as the calculation of all points, with convex hull and then to find the polygon area. At the center of the known rectangle, the vector rotates at the origin reference point and the angle is converted to radians.
/************************************************* author:running_time* Created time:2015/11/10 Tuesday 10:34:43* Fi Le Name:UVA_10652.cpp ************************************************/#include <bits/stdc++.h>using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int N = 1e5 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const Double EPS = 1e-10;c Onst Double PI = ACOs ( -1.0), int dcmp (double x) {if (Fabs (x) < EPS) return 0; else return x < 0? -1:1;} struct point {double x, y; Point () {} A (double x, double y): X (x), Y (y) {} point operator-(const point &r) const {//Vector subtraction Return point (X-r.x, Y-R.Y); } Point operator * (double p) const {//vector multiplied by a scalar return point (x * p, Y * p); } point operator/(double p) const {//vector divided by scalar return point (x/p, y/p); } point operator + (const-point & r) Const {return point (x + r.x, y + r.y); } BOOL operator < (const point &r) const {return x < r.x | | (x = = r.x && y < r.y); } bool operator = = (Const point &r) const {return dcmp (x-r.x) = = 0 && dcmp (y-r.y) = = 0; }};typedef point vector;double dot (vector A, vector B) {//vector dot product return a.x * b.x + a.y * B.Y;} Double Cross (vector A, vector B) {//vector fork product 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));} Double Area_poly (vector<point> PS) {double ret = 0; for (int i=1; i<ps.size ()-1; ++i) {ret + fabs (Cross (Ps[i]-ps[0], ps[i+1]-ps[0])/2; } return ret;} Vector<point> convex_hull (vector<point> PS) {sort (Ps.begin (), Ps.end ()); Ps.erase (Unique (Ps.begin (), Ps.end ()), Ps.end ()); int n = ps.size (), k = 0; Vector<point> Qs (n * 2); for (int i=0; i<n; ++i) {when (K > 1 && Cross (qs[k-1]-qs[k-2], Ps[i]-qs[k-2]) <= 0) k--; qs[k++] = ps[i]; } for (int t=k, i=n-2; i>=0;-I.) {while (K > t && Cross (Qs[k-1]-qs[k-2], Ps[i]-qs[k-2]) < ; = 0) k--; qs[k++] = ps[i]; } qs.resize (k-1); return QS;} int main (void) {int T; scanf ("%d", &t); while (t--) {int n; scanf ("%d", &n); Vector<point> PS; Double area1 = 0; Double x, Y, W, H, R; for (int i=0; i<n; ++i) {scanf ("%lf%lf%lf%lf%lf", &x, &y, &w, &h, &r); Point A = Point (x, y); AREA1 + = w * H; r =-r/180 * PI; Ps.push_back (A + rotate (Vector (-W/2,-H/2), R)); Ps.push_back (A + rotate (Vector (W/2,-H/2), R)); Ps.push_back (A + rotate (Vector (W/2, H/2), R)); Ps.push_back (A + rotate (Vector (-W/2, H/2), R); } vector<point> qs = Convex_hull (PS); printf ("%.1f%%\n", Area1/area_poly (QS)); }//cout << "time Elapsed:" << 1.0 * Clock ()/clocks_per_sec << "s.\n"; return 0;}
Simple geometry (vector rotation + convex hull + polygon area) UVA 10652 Board Wrapping