题目描述
输入格式
输出格式
输入输出样例
输入
1
4
4 7.5 6 3 0
8 11.5 6 3 0
9.5 6 6 3 90
4.5 3 4.4721 2.2361 26.565
输出
64.3 %
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
struct point{
double x,y;
point(){}
point(double a,double b):x(a),y(b){}
bool operator <( const point& d)const{
if(x!=d.x) return x>d.x;
else return y>d.y;
}
point operator - (const point& d){ return point(x-d.x,y-d.y);}
point operator + (const point& d){ return point(x+d.x,y+d.y);}
}num[maxn],ans[maxn];
double Cross(point a,point b){
return a.x*b.y-a.y*b.x;
}
double torad(double j){
return j*acos(-1)/180;
}
int convex(point* p,int n,point* ch){
sort(p,p+n);
int m=0;
for( int i=0; i<n; i++ ){
while( m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
int k=m;
for( int i=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--;
return m;
}
double PolygonArea(point* ch,int n){
double ans=0;
for( int i=1; i<n; i++ ) ans+=Cross(ch[i]-ch[0],ch[i+1]-ch[0])/2;
return ans;
}
point Rotate(point buf,double ang){
return point(buf.x*cos(ang)-buf.y*sin(ang),buf.x*sin(ang)+buf.y*cos(ang));
}
int main(){
int t;scanf("%d",&t);
while(t--){
int n,cnt=0;scanf("%d",&n);
double area1=0;
double x,y,w,h,j,ang;
for( int i=0; i<n; i++ ){
scanf("%lf %lf %lf %lf %lf",&x,&y,&w,&h,&j);
point o(x,y);
ang=-torad(j);
num[cnt++]=o+Rotate(point(w/2,h/2),ang);
num[cnt++]=o+Rotate(point(-w/2,h/2),ang);
num[cnt++]=o+Rotate(point(w/2,-h/2),ang);
num[cnt++]=o+Rotate(point(-w/2,-h/2),ang);
area1+=w*h;
}
int m=convex(num,cnt,ans);
double area2=PolygonArea(ans,m);
printf("%.1lf %\n",area1/area2*100);
}
return 0;
}