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个长方形,用一个面积尽量小的凸多边形把他们围起来 求木板占包装面积的百分比 输入给出长方形的中心坐标,长,宽,以及长方形 ...
随机推荐
- 【原创】ASP.NET Web开发,实现打印Log日志,步骤详解
添加Log需要四步: 一.引用log4net.dll,详见附件:http://pan.baidu.com/s/1c0hab2g 二.项目根目录下,添加 log4net.xml <?xml ver ...
- 使用Notepad++快速有效删除复制代码中的行号
转载:http://plum.0602.blog.163.com/blog/static/1130006502011101524120757/ 试了该方法,很好用! 为什么我把用Notepad++删除 ...
- spring 加载配置文件的相关配置总结
PropertyPlaceholderConfigurer 注意: Spring容器仅允许最多定义一个PropertyPlaceholderConfigurer(或<context:p ...
- UltraISO做U盘启动盘教程
用UltraISO做U盘启动盘教程 注意:制作前请先备份u盘内重要文件 vista.win7系统需要以管理员身份运行UltraISO,其他系统直接运行即可 1.打开UltraISO选择iso镜像文件 ...
- Python 3 学习笔记
教程地址: http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143161198 ...
- BZOJ 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏( floyd )
直接floyd.. ---------------------------------------------------------------------------- #include<c ...
- win7 64位的PHP5.4安装redis扩展
先看phpinfo.php信息 可以看是 PHP5.4 VC9 TS Architecture x86 说明是x86的PHP,虽然系统是64位的,所以还是要下载x86的redis 然后Github下载 ...
- python的虚拟运行环境
Python 虚拟环境:Virtualenv 博客分类: Python python 在进行python开发的时候避免不同版本python或python不同版本组件之间的冲突, 有必要配置python ...
- nginx+tomcat+redis完成session共享
本文记录nginx+redis+tomcat实现session共享的过程 nginx安装:http://blog.csdn.net/grhlove123/article/details/4783467 ...
- 网络收发之cycleBuf
#pragma once #include <iostream> #include <string> class cyclebuffer { protected: volati ...