uva 10652 Board Wrapping

时间:2022-05-03 22:37:20

主要是凸包的应用;

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#define eps 1e-9
using namespace std;
const double pi = acos(-); int dcmp(double x)
{
return fabs(x) < eps ? : (x > ? : -);
} struct Point
{
double x;
double y; Point(double x = , double y = ):x(x), y(y) {} bool operator < (const Point& e) const
{
return dcmp(x - e.x) < || (dcmp(x - e.x) == && dcmp(y - e.y) < );
} bool operator == (const Point& e) const
{
return dcmp(x - e.x) == && dcmp(y - e.y) == ;
}
}; typedef Point Vector; Vector operator + (Point A, Point 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);
} Vector operator * (Point A, double p)
{
return Vector(A.x * p, A.y * p);
} Vector operator / (Point A, double p)
{
return Vector(A.x / p, A.y / p);
} double cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
Point rotate(Point a,double ang){return Point(a.x*cos(ang)-a.y*sin(ang),a.x*sin(ang)+a.y*cos(ang));}
int convexhull(Point *p,int n,Point *ch)
{
sort(p,p+n);
int m=;
for(int i=;i<n;i++)
{
while(m>&&cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--)
{
while(m>k&&cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
if(n>)m--;
return m;
}
Point p[],ch[];
int main()
{
int t,n;
double alph,x,y,h,w,area1,area2;
scanf("%d",&t);
while(t--)
{
area1=area2=;
scanf("%d",&n);
int pc=;
for(int i=;i<n;i++)
{
scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&alph);
Point o(x,y);
double ang=-(alph*pi/);
p[pc++]=o+rotate(Point(-w/,-h/),ang);
p[pc++]=o+rotate(Point(w/,-h/),ang);
p[pc++]=o+rotate(Point(-w/,h/),ang);
p[pc++]=o+rotate(Point(w/,h/),ang);
area1+=w*h;
}
int m=convexhull(p,pc,ch);
for(int i=;i<m;i++)
area2+=cross(ch[i]-ch[],ch[i+]-ch[]);
area2/=;
printf("%.1lf ",area1/area2*);
puts("%");
}
return ;
}