Input: standard input
Output: standard output

Time Limit: 2 seconds

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 n, 1< 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 %


Swedish National Contest

The Sample Input and Sample Output corresponds to the given picture

题解:白书上的原题。

把每个矩形的四个顶点都找出来,做凸包就是最小的多边形,计算面积就从一个点出发向每个点都连一条对角线,将多边形分成若干个三角形再计算。

比较坑的是,数字和“%”之间还有一个空格>_<!


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<ctime>
#include<string>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL inf=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-10; struct Point{
double x,y;
Point(double xx=0,double yy=0) : x(xx),y(yy) {}
} p[2010],ch[2010];
typedef Point Vector;//定义向量 Vector operator + (Vector a,Vector b) { return Vector(a.x+b.x,a.y+b.y); }
Vector operator - (Vector a,Vector b) { return Vector(a.x-b.x,a.y-b.y); }
Vector operator * (Vector a,Vector b) { return Vector(a.x*b.x,a.y*b.y); }
Vector operator / (Vector a,Vector b) { return Vector(a.x/b.x,a.y/b.y); }
bool operator < (const Point &a,const Point &b) { return a.x==b.x? a.y<b.y:a.x<b.x; } int dcmp(double x)//精度判断
{
if(fabs(x)<eps) return 0;
return x<0 ? -1 : 1;
} double Dot(Vector a,Vector b) { return a.x*b.x+a.y*b.y; } //点积,向量积
double Cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; }//叉积
double Length(Vector a) { return sqrt(Dot(a,a)); }//向量长度
double Angle(Vector a,Vector b) { return acos(Dot(a,b)/Length(a)/Length(b)); }//向量的夹角
Vector Rotate(Vector a,double rad) { return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad)); }//逆时针旋转rad
Vector Normal(Vector a){ return Vector(-a.y/Length(a),a.x/Length(a)); }//单位法向量
double torad(double deg) { return deg/180*acos(-1); }//角度转化为弧度 Point GetLineIntersection(Point p,Vector v,Point q,Vector w)//两直线交点
{
Vector u=p-q;
double t=Cross(w,u)/Cross(v,w);
return p+v*t;
} double DistanceToLine(Point p,Point a,Vector b)//点到直线距离
{
Vector v1=b-a,v2=p-a;
return fabs(Cross(v1,v2))/Length(v1);
}
/*
double DistanceToSegment(Point p,Point a,Point b)//点到线段距离
{
if(a==b) return Length(p-a);
Vector v1=b-a,v2=p-a,v3=p-b;
if(dcmp(Dot(v1,v2))<0) return Length(v2);
else if(dcmp(Dot(v1,v3))>0) return Length(v3);
else return fabs(Cross(v1,v2))/Length(v1);
}
*/
Point GetLineProjection(Point p,Point a,Point b)//点在直线的投影点
{
Vector v=b-a;
return a+v*(Dot(v,p-a)/Dot(v,v));
} double Polygonarea(Point *p,int n)//多边形面积(凸,凹)
{
double area=0;
for(int i=1;i<n-1;i++) area+=Cross(p[i]-p[0],p[i+1]-p[0]);
return area/2;
} int Convexhull(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;
} int N,n;
double x,y,w,h,j; int main()
{
scanf("%d",&N);
while(N--)
{
int flag=0;
double area1=0,area2=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j);
Point O{x,y};
double rad=-torad(j);
p[flag++]=O + Rotate(Vector(-w/2,-h/2),rad);
p[flag++]=O + Rotate(Vector(w/2,-h/2),rad);
p[flag++]=O + Rotate(Vector(-w/2,h/2),rad);
p[flag++]=O + Rotate(Vector(w/2,h/2),rad);
area1+=w*h;
}
int cnt=Convexhull(p,flag,ch);
area2=Polygonarea(ch,cnt);
printf("%.1lf %%\n",area1*100/area2);
}
return 0;
}

  


UVa-10652 包装木板的更多相关文章

  1. UVA 10652 Board Wrapping(二维凸包)

    传送门 刘汝佳<算法竞赛入门经典>P272例题6包装木板 题意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们抱起来,并计算出木板占整个包装面积的百分比. 输入:t组数据,每组 ...

  2. uva 10652

    大意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们包起来,并计算出木板站整个包装面积的百分比. 思路:按照题意将所有矩形顶点坐标存起来,旋转时先旋转从中心出发的向量,求得各个坐标之后,求 ...

  3. uva 10652 Board Wrapping (计算几何-凸包)

    Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The sma ...

  4. UVa 10652 (简单凸包) Board Wrapping

    题意: 有n块互不重叠的矩形木板,用尽量小的凸多边形将它们包起来,并输出并输出木板总面积占凸多边形面积的百分比. 分析: 几乎是凸包和多边形面积的裸题. 注意:最后输出的百分号前面有个空格,第一次交P ...

  5. 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping

    题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...

  6. uva 10652 Board Wrapping

    主要是凸包的应用: #include <cstdio> #include <cmath> #include <cstring> #include <algor ...

  7. UVA 10652 Board Wrapping(凸包)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32286 [思路] 凸包 根据角度与中心点求出长方形所有点来,然后就 ...

  8. Uva 10652 Board Wrapping(计算几何之凸包+点旋转)

    题目大意:给出平面上许多矩形的中心点和倾斜角度,计算这些矩形面积占这个矩形点形成的最大凸包的面积比. 算法:GRAHAM,ANDREW. 题目非常的简单,就是裸的凸包 + 点旋转.这题自己不会的地方就 ...

  9. UVA 10652 Board Wrapping(凸包)

    The small sawmill in Mission, British Columbia, hasdeveloped a brand new way of packaging boards for ...

  10. ●UVA 10652 Board Wrapping

    题链: https://vjudge.net/problem/UVA-10652 题解: 计算几何,Andrew求凸包, 裸题...(数组开小了,还整了半天...) 代码: #include<c ...

随机推荐

  1. 重写(OverRide)/重载(Overload)

    方法的重写规则 参数列表必须完全与被重写方法的相同: 返回类型与被重写方法的返回类型可以不相同,但是必须是父类返回值的派生类(java5 及更早版本返回类型要一样,java7 及更高版本可以不同): ...

  2. C# Web分页功能实现

    无论是网站还是APP分页功能都是必不可少的.为什么使用分页呢? 1,加载速度快,不会占用服务器太多资源,减少服务器压力. 2,减少数据库压力. 3,提升用户体验. 那么我们常用的分页方法有两种. 1, ...

  3. 注意android辅助服务事件不能用于保存

    本来希望把来自辅助服务的事件,像epoll那样暂存在队列进行调度,或者做成事件堆栈,从而将辅助服务事件加入到容器.但是一直不能达到预期的后果.最后才发现一个坑人的事实,辅助服务事件被释放(或者说重置) ...

  4. 十、GAP

    1.1     背景 GAP(Generic Access Profile)位于主机协议栈的最顶层,用来定义BLE设备在待机或者连接状态中的行为,该Profile保证不同的Bluetooth产品可以互 ...

  5. SQL Server Management Studio 安装流程

    数据库的操作需要使用SQL Server Management Studio,不过也可以使用其他的: 下面是安装操作的步骤:如果你下载的压缩包,你需要先解压到一个文件夹里,然后双击setup.exe, ...

  6. salesforce lightning零基础学习(十五) 公用组件之 获取表字段的Picklist(多语言)

    此篇参考:salesforce 零基础学习(六十二)获取sObject中类型为Picklist的field values(含record type) 我们在lightning中在前台会经常碰到获取pi ...

  7. PHP提高SESSION响应速度的方法有哪些

    1.设置多级目录存储SESSION 默认session的存储目录是1级目录,如果用户量比较大,session文件数量就比较大,我们可以设置目录数为2,使用2级目录可以提交查找和存取速度.不过这种方式对 ...

  8. alpha week 2/2 Scrum立会报告+燃尽图 01

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9798 一.小组情况 队名:扛把子 组长:迟俊文 组员:宋晓丽 梁梦瑶 韩昊 ...

  9. D^3ctf两道 pwn

    这次 的D^3ctf 又是给吊打 难顶... 所以题都是赛后解出来的,在这感谢Peanuts师傅 unprintableV 看看保护: 看看伪代码,其实代码很少 void __cdecl menu() ...

  10. element 根据某一个属性合并列

    通过 span-method 绑定方法 objectSpanMethod方法 this.getSpanArr(this.tableData); //this.tableData 指接口取到的数据 // ...