UVA10652 Board Wrapping

27 篇文章 0 订阅
3 篇文章 0 订阅

题目描述

在这里插入图片描述

输入格式

在这里插入图片描述

输出格式

在这里插入图片描述

输入输出样例

输入

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;
}
//计算凸包,输入点数组p,个数为n,输出点数组ch,返回值为凸包定点数 
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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值