UVA 10652 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 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, ϕ where 0 ≤ x, y, w, h ≤ 10000
and −90◦ < ϕ ≤ 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. ϕ is the angle between the height axis of the board to the
y-axis in degrees, positive clockwise. That is, if ϕ = 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 (‘%’).
Note: The Sample Input and Sample Output corresponds to the given picture
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
Sample Output
64.3 %
题解:求矩形面积与凸包面积的比例,顺时针一定要是负....错了半天。。。还有给的ang要转化为rad
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const double Pi=acos(-1.0);
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y){}
};
typedef Point Vector;
bool operator < (Point a,Point b){return a.x<b.x||(a.x==b.x&&a.y<b.y);}
Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
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));}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
Point operator + (Point a,Vector b){return Point(a.x+b.x,a.y+b.y);}
Point getdot(Point a,Vector b,double ang){return a+Rotate(b,ang);}
double getrad(double ang){return Pi*(ang/);}
Point ans[],at[];
int nu;
double polygonArea(){
int k=;
for(int i=;i<nu;i++){
while(k>&&Cross(ans[k-]-ans[k-],at[i]-ans[k-])<=)k--;
ans[k++]=at[i];
}
int p=k;
for(int i=nu-;i>=;i--){
while(k>p&&Cross(ans[k-]-ans[k-],at[i]-ans[k-])<=)k--;
ans[k++]=at[i];
}
double x=;
k--;
if(k<)return ;
for(int i=;i<k-;i++)x+=Cross(ans[i]-ans[],ans[i+]-ans[]);
return x/;
}
int main(){
int T,n;
double x,y,w,h,ang;
scanf("%d",&T);
while(T--){
double area1=,area2=;
nu=;
scanf("%d",&n);
while(n--){
scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&ang);
area2+=w*h;
Point a;
ang=-getrad(ang);//因为是顺时针旋转的,所以要是负的。。。。。
at[nu++]=getdot(Point(x,y),Vector(w/,h/),ang);
at[nu++]=getdot(Point(x,y),Vector(-w/,h/),ang);
at[nu++]=getdot(Point(x,y),Vector(w/,-h/),ang);
at[nu++]=getdot(Point(x,y),Vector(-w/,-h/),ang);
}
sort(at,at+nu);
area1=polygonArea();
// printf("%lf %lf\n",area1,area2);
printf("%.1lf %%\n",*area2/area1);
}
return ;
}
UVA 10652 Board Wrapping(凸包)的更多相关文章
- uva 10652 Board Wrapping (计算几何-凸包)
Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The sma ...
- UVA 10652 Board Wrapping 计算几何
多边形凸包.. .. Board Wrapping Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu ...
- 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping
题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...
- UVA 10652 Board Wrapping(凸包)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32286 [思路] 凸包 根据角度与中心点求出长方形所有点来,然后就 ...
- Uva 10652 Board Wrapping(计算几何之凸包+点旋转)
题目大意:给出平面上许多矩形的中心点和倾斜角度,计算这些矩形面积占这个矩形点形成的最大凸包的面积比. 算法:GRAHAM,ANDREW. 题目非常的简单,就是裸的凸包 + 点旋转.这题自己不会的地方就 ...
- UVA 10652 Board Wrapping(二维凸包)
传送门 刘汝佳<算法竞赛入门经典>P272例题6包装木板 题意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们抱起来,并计算出木板占整个包装面积的百分比. 输入:t组数据,每组 ...
- uva 10652 Board Wrapping
主要是凸包的应用: #include <cstdio> #include <cmath> #include <cstring> #include <algor ...
- ●UVA 10652 Board Wrapping
题链: https://vjudge.net/problem/UVA-10652 题解: 计算几何,Andrew求凸包, 裸题...(数组开小了,还整了半天...) 代码: #include<c ...
- uva 10625 Board Wrapping
https://vjudge.net/problem/UVA-10652 给出n个长方形,用一个面积尽量小的凸多边形把他们围起来 求木板占包装面积的百分比 输入给出长方形的中心坐标,长,宽,以及长方形 ...
随机推荐
- Ajax学习之小结
ajax: * 同步交互和异步交互: * 同步交互:客户端发送请求——>等待服务器端处理——>接收响应,这个过程客户端不能做任何其他事情,这种模式叫做同步交互 * 异步交互:客户端发送 ...
- 关于asp.net 的一些好资料地址 , 防止丢失!
学习数据结构的好网站 : http://student.zjzk.cn/course_ware/data_structure/web/practice/practice1.htm http://www ...
- codeforces 522D. Closest Equals 线段树+离线
题目链接 n个数m个询问, 每次询问输出给定区间中任意两个相同的数的最近距离. 先将询问读进来, 然后按r从小到大排序, 将n个数按顺序插入, 并用map统计之前是否出现过, 如果出现过, 就更新线段 ...
- (Problem 42)Coded triangle numbers
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...
- wordpress 首页模板变量对应表
最近开始学习wp,这里做一些笔记. 首页模板,第一行为前台显示的html代码.第二行为 wp-content/themes/模板目录 下 head.php文件中. 其中我将变量名 html用绿色标记 ...
- QT 子窗口监听主窗口信号(超级简单,但是好用,比如主窗口移动的时候,子窗口不要再继续处理任务)
MainWindow *ptr = NULL; ptr = (MainWindow*)parentWidget(); connect(ptr, SIGNAL(param_result(bool)), ...
- Spinner样式大全
Spinner样式大全
- Windows Azure 即将更名
今天我们宣布自2014 年4 月3 日起,WindowsAzure 将更名为Microsoft Azure.这一更名反映了Microsoft 的战略,并显示了Microsoft 专注于将Azur ...
- Ubuntu 12.10 安装JDK7
1.首先到oracle下载上下载jdk-7u25-linux-i586.tar.gz 2.将jdk-7u25-linux-i586.tar.gz复制到/usr/lib/jvm/目录以下,这里假设没有j ...
- 初探swift语言的学习—Object-C与Swift混编
swift 语言出来后,可能新的项目直接使用swift来开发,但可能在过程中会遇到一些情况,某些已用OC写好的类或封装好的模块,不想再在swift 中再写一次,哪就使用混编.这个在IOS8中是允许的. ...