Board Wrapping




The small sawmill in Mission, British Columbia, has developed a brand new way of packaging boards for drying. By fixating the boards in special moulds, the board can dry efficiently in a drying room.

Space is an issue though. The boards cannot be too close, because then the drying will be too slow. On the other hand, one wants to use the drying room efficiently.

Looking at it from a 2-D perspective, your task is to calculate the fraction between the space occupied by the boards to the total space occupied by the mould. Now, the mould is surrounded by an aluminium frame of negligible thickness, following the hull of the boards' corners tightly. The space occupied by the mould would thus be the interior of the frame.

 

 

 

Input

On the first line of input there is one integer, N <= 50, giving the number of test cases (moulds) in the input. After this line, N test cases follow. Each test case starts with a line containing one integer n1< n <= 600, which is the number of boards in the mould. Then n lines follow, each with five floating point numbers x, y, w, h, j where 0 <= x, y, w, h <=10000 and –90° < j <=90°. The x and y are the coordinates of the center of the board and w and h are the width and height of the board, respectively. j is the angle between the height axis of the board to the y-axis in degrees, positive clockwise. That is, if j = 0, the projection of the board on the x-axis would be w. Of course, the boards cannot intersect.

 

Output

For every test case, output one line containing the fraction of the space occupied by the boards to the total space in percent. Your output should have one decimal digit and be followed by a space and a percent sign (%).

 

Sample Input                              Output for Sample Input

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<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

const double Pi=acos(-1.0);
const double eps=1e-6;
int dcmp(double x)
{
	if(fabs(x)<eps) return 0;
	else return x>0 ? 1:-1;
}

struct point{
	double x,y;
	point() {}
	point(double x,double y):x(x),y(y) {}
	point operator +(const point &b) const {return point(x+b.x,y+b.y);}
	point operator -(const point &b) const {return point(x-b.x,y-b.y);}
	point operator *(const double &b) const {return point(x*b,y*b);}
	point operator /(const double &b) const {return point(x/b,y/b);}
	bool operator <(const point &b) const {return dcmp(x-b.x)<0||(dcmp(x-b.x)==0&&dcmp(y-b.y)<0);}
}a[2410],b[2410];

double det(const point &a,const point &b) {return a.x*b.y-a.y*b.x;}

point Rotate(point p,double A)
{
	return point(p.x*cos(A)-p.y*sin(A),p.x*sin(A)+p.y*cos(A));
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--) {
		int n,k=0;
		scanf("%d",&n);
		double w,h,rad,sum=0.0,sum1=0.0;
		point s;
		for(int i=0;i<n;i++) {
			scanf("%lf%lf%lf%lf%lf",&s.x,&s.y,&w,&h,&rad);
			sum+=w*h;
			point p1=point(s.x-w/2.0,s.y-h/2.0),p2=point(s.x-w/2.0,s.y+h/2.0);
			point p3=point(s.x+w/2.0,s.y-h/2.0),p4=point(s.x+w/2.0,s.y+h/2.0);
			rad=rad/180*Pi;
			a[k++]=s+Rotate(p1-s,-rad);
			a[k++]=s+Rotate(p2-s,-rad);
			a[k++]=s+Rotate(p3-s,-rad);
			a[k++]=s+Rotate(p4-s,-rad);
		}
		sort(a,a+k);
		int j=0;
		for(int i=0;i<k;i++) {
			while(j>1&&dcmp(det(b[j-1]-b[j-2],a[i]-b[j-2]))<=0) j--;
			b[j++]=a[i];
		}
		int tmp=j;
		for(int i=k-2;i>=0;i--) {
			while(j>tmp&&dcmp(det(b[j-1]-b[j-2],a[i]-b[j-2]))<=0) j--;
			b[j++]=a[i];
		}
		for(int i=0;i<j-1;i++) sum1+=det(b[i],b[i+1]);
		sum1/=2.0;
		sum=sum/sum1*100.0;
		printf("%.1lf %%\n",sum);
	}
	return 0;
}



The small sawmill in Mission, British Columbia, has developed a brand new way of packaging boards for drying. By fixating the boards in special moulds, the board can dry efficiently in a drying room.

Space is an issue though. The boards cannot be too close, because then the drying will be too slow. On the other hand, one wants to use the drying room efficiently.

Looking at it from a 2-D perspective, your task is to calculate the fraction between the space occupied by the boards to the total space occupied by the mould. Now, the mould is surrounded by an aluminium frame of negligible thickness, following the hull of the boards' corners tightly. The space occupied by the mould would thus be the interior of the frame.

 

 

 

Input

On the first line of input there is one integer, N <= 50, giving the number of test cases (moulds) in the input. After this line, N test cases follow. Each test case starts with a line containing one integer n1< n <= 600, which is the number of boards in the mould. Then n lines follow, each with five floating point numbers x, y, w, h, j where 0 <= x, y, w, h <=10000 and –90° < j <=90°. The x and y are the coordinates of the center of the board and w and h are the width and height of the board, respectively. j is the angle between the height axis of the board to the y-axis in degrees, positive clockwise. That is, if j = 0, the projection of the board on the x-axis would be w. Of course, the boards cannot intersect.

 

Output

For every test case, output one line containing the fraction of the space occupied by the boards to the total space in percent. Your output should have one decimal digit and be followed by a space and a percent sign (%).

 

Sample Input                              Output for Sample Input

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 %

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值