当前位置: 代码迷 >> 综合 >> UVA 10652 Board Wrapping .
  详细解决方案

UVA 10652 Board Wrapping .

热度:48   发布时间:2023-09-23 04:02:12.0

题目地址:https://vjudge.net/problem/UVA-10652

模板题

注意顺时针为正,并且输入的是度数而不是弧度值

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b)  for(int i=a;i<=(int)(b);++i)
#define REPD(i,a,b) for(int i=a;i>=(int)(b);--i)
const double PI=acos(-1);
const double EPS=1e-8;
int dcmp(double x){if(fabs(x)<EPS) return 0;return x > 0 ? 1 : -1;
}
struct Point
{double x,y;
};
typedef Point Vector;
bool operator < (const Point& p1, const Point& p2){return p1.x<p2.x || (p1.x==p2.x && p1.y<p2.y) ;
}
Vector operator / (const Point& A, double x){return Vector{A.x/x, A.y/x};
}
Vector operator * (const Vector& A, double x){return Vector{A.x*x, A.y*x};
}
Vector operator - (const Vector& A, const Vector& B){return Vector{A.x-B.x,A.y-B.y};
}
Vector operator + (const Point& A, const Vector& v){return Point{A.x+v.x,A.y+v.y};
}
Vector Rotate(const Point& p,double ang){return Vector{p.x*cos(ang)-p.y*sin(ang),p.x*sin(ang)+p.y*cos(ang)};
}
double Cross(const Vector& A, const Vector& B){return A.x*B.y-A.y*B.x;
}
double Dot(Vector A, Vector B){return A.x*B.x+A.y*B.y;
}
double Length(Vector v){return sqrt(Dot(v,v));
}
Vector Unit(Vector v){return v/Length(v);
}
const int maxn=600+5;
Point points[maxn*4];
Point ch[maxn*2];
int ConvexHull(Point* A,int n,Point* B){sort(A,A+n);int m=0;REP(i,0,n-1){while(m>1 && dcmp(Cross(B[m-1]-B[m-2],A[i]-B[m-1])) < 0) m--;B[m++]=A[i];}int k=m;REPD(i,n-2,0){while(m>k && dcmp(Cross(B[m-1]-B[m-2],A[i]-B[m-1])) < 0) m--;B[m++]=A[i];}return m-1;
}
int main(int argc, char const *argv[])
{// freopen("input.in","r",stdin);int T; scanf("%d",&T);while(T--){int n; scanf("%d",&n);int pCnt=0;double tot=0.;REP(i,1,n){double x,y,w,h,ang;scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&ang);Point p=Point{x,y};Vector Vx=Rotate(Vector{1,0},-ang/180*PI);Vector Vy=Rotate(Vx,PI/2);points[pCnt++]=p+Vx*(w/2)+Vy*(h/2);points[pCnt++]=p+Vx*(w/2)-Vy*(h/2);points[pCnt++]=p-Vx*(w/2)+Vy*(h/2);points[pCnt++]=p-Vx*(w/2)-Vy*(h/2);tot+=w*h;}int cnt=ConvexHull(points,pCnt,ch);double Area=0.;REP(i,1,cnt-2)	Area+=Cross(ch[i]-ch[0],ch[i+1]-ch[0]);printf("%.1lf %%\n", tot*200/Area);}return 0;
}