Title Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32286
Ideas
Convex bag
According to the angle and the center point to find the rectangle all points, and then you can apply the convex hull algorithm.
Code
#include <cmath>#include<cstdio>#include<algorithm>using namespacestd;Const DoublePI = ACOs (-1.0);DoubleTorad (DoubleDEG) {returndeg/ the* PI; }//Angled radiansstructPt {Doublex, y; Pt (Doublex=0,Doubley=0): X (x), Y (y) {};}; typedef Pt VEC;VECoperator-(Pt a,pt B) {returnVEC (a.x-b.x,a.y-b.y); }vecoperator+ (VEC A,vec B) {returnVEC (a.x+b.x,a.y+b.y); }BOOL operator< (Constpt& A,Constpt&b) {returna.x<b.x | | (a.x==b.x && a.y<b.y);}DoubleCross (Pt a,pt B) {returna.x*b.y-a.y*b.x;} Vec rotate (Vec A,Doublerad) { returnVEC (A.x*cos (RAD)-a.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD));}intConvexhull (pt* p,intn,pt*ch) {Sort (p,p+N); intm=0; for(intI=0; i<n;i++) { while(m>1&& Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--;//Maintenance Convex bagch[m++]=P[i]; } intk=m; for(inti=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--; returnm;}DoublePolygonarea (pt* p,intN) {//Polygon Area Doubles=0; for(intI=1; i<n-1; i++) S+ = Cross (p[i]-p[0],p[i+1]-p[0]); returns/2;}Const intN =2500+Ten; Pt P[n],ch[n];intN;intMain () {intT; scanf ("%d",&T); while(t--) {scanf ("%d",&N); intPc=0;Doubles1=0; Doublex,y,w,h,j; for(intI=0; i<n;i++) {scanf ("%LF%LF%LF%LF%LF",&x,&y,&w,&h,&K); Doubleang=-Torad (j); Pt o (x, y); P[PC++]= o + rotate (VEC (-w/2,-h/2), ANG); P[PC++]= o + rotate (VEC (w/2,-h/2), ANG); P[PC++]= o + rotate (VEC (-w/2, h/2), ANG); P[PC++]= o + rotate (VEC (w/2, h/2), ANG); S1+ = w*h; } intm=Convexhull (P,PC,CH); DoubleS2=Polygonarea (ch,m); printf ("%.1LF%%\n", s1* -/S2); } return 0;}
UVA 10652 Board Wrapping (convex bag)