Chain of title:
https://vjudge.net/problem/UVA-10652
Exercises
Calculate geometry, Andrew asks for convex hull,
Bare title ... (The array is small, but also the whole day ...) )
Code:
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < Algorithm> #define MAXN 650using namespace Std;const double Eps=1e-8,pi=acos ( -1); int sign (double x) {if (Fabs (x) <= EPS) return 0;return x<0?-1:1;} struct point{double x, y; Point (Double _x=0,double _y=0): X (_x), Y (_y) {}};typedef-point vector;bool operator < (const-point-A,const point B) {retur N sign (a.x-b.x) <0| | (sign (a.x-b.x) ==0&&sign (A.Y-B.Y) <0);} BOOL operator = = (Point a,point B) {return sign (a.x-b.x) ==0&&sign (A.Y-B.Y) ==0;} Vector operator + (vector a,vector B) {return vector (A.X+B.X,A.Y+B.Y);} Vector operator-(point A,point B) {return Vector (A.X-B.X,A.Y-B.Y);} Double operator ^ (Vector a,vector B) {return a.x*b.y-a.y*b.x;} Point D[maxn*4],c[maxn*4];d ouble torad (double deg) {return deg/180*pi;} Angle to radians vector rotate (vector a,double angle) {//vector A counterclockwise rotation angle (radians) return vector (A.x*cos (angle)-a.y*sin (angle), A.x*sin (angle) +a.y*cos (angle));} int Andrew (int dnt) {int cnt=0,k=0;sorT (d+1,d+dnt+1); Dnt=unique (d+1,d+dnt+1)-d-1;for (int i=1;i<=dnt;i++) {while (cnt>1&& ((c[cnt]-c[cnt-1)) ^ (D[i]-C[cnt-1 ])) <=0) cnt--; C[++cnt]=d[i];} k=cnt;for (int i=dnt-1;i>=1;i--) {while (cnt>k&& ((c[cnt]-c[cnt-1]) ^ (d[i]-c[cnt-1)) <=0) cnt--; C[++cnt]=d[i];} return CNT;} Double Polygonarea (int cnt) {double area=0;for (int i=1;i<cnt;i++) area+= (c[i]^c[i+1])/2;return area; int main () {double area1,area2,x,y,w,h,angle;int case,n,dnt,cnt; scanf ("%d", &case), while (case--) {area1=area2= DNT=CNT=0;SCANF ("%d", &n), for (int i=1;i<=n;i++) {scanf ("%LF%LF%LF%LF%LF",&x,&y,&w,&h,& Angle) Angle=-torad (angle);D [++dnt]=point (x, y) +rotate (vector (W/2,H/2), angle);D [++dnt]=point (x, y) +rotate (vector (-W/2,H/2), angle);D [++dnt]=point (x, y) +rotate (vector (W/2,-H/2), angle);D [++dnt]=point (x, y) +rotate (vector (-w/2,-h /2), angle); area1+=w*h;} Cnt=andrew (DNT),//printf ("%d\n", CNT), Area2=polygonarea (CNT);p rintf ("%.1lf%%\n", AREA1*100/AREA2);} return 0;}
UVA 10652 Board Wrapping