Problem B

Board Wrapping

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 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 %


Swedish National Contest

The Sample Input and Sample Output corresponds to the given picture

题目大意:

给n个矩形木板,你要用一个面积尽量小的凸多边形把它们包起来,求木板占整个包装面积的百分比。

解题思路:

最主要还是求凸包。

解题代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std; const double eps=1e-7;
struct Point{
double x,y;
Point(double x0=0,double y0=0){
x=x0,y=y0;
}
void read(){ scanf("%lf%lf",&x,&y); }
friend bool operator < (Point a,Point b){
if(a.y!=b.y) return a.y<b.y;
else return a.x<b.x;
}
double getdis(Point q){ return sqrt( (x-q.x)*(x-q.x)+(y-q.y)*(y-q.y) ); }
}; 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,double p) { return Vector(A.x*p,A.y*p); }
Vector operator / (Vector A,double p) { return Vector(A.x/p,A.y/p); } int dcmp(double x) { if(fabs(x)<eps) return 0; else return x<0?-1:1; }
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)); }
double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x; }
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弧度
double torad(double ang){ return ang/180.0*acos(-1.0); } const int maxn=2500;
Point p[maxn];
int n,top;
double sum; bool cmp(Point a,Point b){
if( fabs( Cross(a-p[0],b-a) )<eps ) return a.getdis(p[0])<b.getdis(p[0]);
else return Cross(a-p[0],b-a)>0;
} double ConvexHull(){
top=1;
sort(p,p+n);
sort(p+1,p+n,cmp);
for(int i=2;i<n;i++){
while(top>0 && Cross(p[top]-p[top-1],p[i]-p[top-1])<=0) top--;
p[++top]=p[i];
}
p[++top]=p[0];
double area=0;
for(int i=1;i<top;i++){
area+=Cross(p[i]-p[0],p[i+1]-p[0]);
}
return area/2.0;
} void input(){
n=0;
sum=0;
int m;
scanf("%d",&m);
for(int i=0;i<m;i++){
Point o;
double w,h,ang,rad;
scanf("%lf%lf%lf%lf%lf",&o.x,&o.y,&w,&h,&ang);
rad=-torad(ang);
p[n++]=o+Rotate(Vector(-w/2.0,-h/2.0),rad);
p[n++]=o+Rotate(Vector(-w/2.0,h/2.0),rad);
p[n++]=o+Rotate(Vector(w/2.0,h/2.0),rad);
p[n++]=o+Rotate(Vector(w/2.0,-h/2.0),rad);
sum+=w*h;
}
} void solve(){
double ans=ConvexHull();
printf("%.1lf %%\n",sum*100.0/ans);
} int main(){
int T;
scanf("%d",&T);
while(T-- >0){
input();
solve();
}
return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

uva 10652 Board Wrapping (计算几何-凸包)的更多相关文章

  1. UVA 10652 Board Wrapping 计算几何

    多边形凸包.. .. Board Wrapping Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu ...

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

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

  3. UVA 10652 Board Wrapping(凸包)

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

  4. UVA 10652 Board Wrapping(凸包)

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

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

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

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

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

  7. ●UVA 10652 Board Wrapping

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

  8. uva 10652 Board Wrapping

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

  9. uva 10625 Board Wrapping

    https://vjudge.net/problem/UVA-10652 给出n个长方形,用一个面积尽量小的凸多边形把他们围起来 求木板占包装面积的百分比 输入给出长方形的中心坐标,长,宽,以及长方形 ...

随机推荐

  1. ftp的主动模式(port)与被动模式(PASV) (转)

    FTP是仅基于TCP的服务,不支持UDP.与众不同的是FTP使用2个端口,一个数据端口和一个命令端口(也可叫做控制端口).通常来说这两个端口是21(命令端口)和20(数据端口).但FTP工作方式的不同 ...

  2. MIPS台OpenWrt在系统内的路由器Rust应用程序开发

    笔者:Liigo(庄小莉) 迄今:2014年9一个月17日本 (9一个月29日更新,11一个月19日本再次更新.在最后可用更新) 原文链接:http://blog.csdn.net/liigo/art ...

  3. Heibernate 入门笔记(一)---第一个demo

    最近在学heibernate,是看马士兵老师的视频学的,在这里总结一下,做点笔记.关于heibernate的优点,大家可以在网上 百度,这里不做赘述,直接讲怎么使用heibernate 步骤一:新建项 ...

  4. java基础程序题

    发现自己初学java时保存在word里的练习题,哈哈,放博客里面来作为纪念吧~~~ [程序1]  题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔 ...

  5. android存储阵列数据SharedPreferences

    假设要数组数据(如boolean[] .int[]等)到SharedPreferences时,我们能够先将数组数据组织成json数据存储到SharedPreferences,读取时则对json数据进行 ...

  6. iOS 8 新特性

    这篇文章会介绍iOS8开发相关的主要特性. App 插件 通过支持插件,iOS8让我们可以系统指定的区域进行扩展,也就是为用户的特定需求提供自定义的方法.例如:可以通过App插件帮助用户分享他们的内容 ...

  7. 同ListView该接口无法通过手势滑动左右切换界面问题解决方法

    同ListView该接口无法通过手势滑动左右切换界面问题解决方法 问题描写叙述: 在做OnGestureListener滑动切换窗体的时候,会遇到这种问题.就是当界面中含有ListView的时候.On ...

  8. Python计算&绘图——曲线拟合问题(转)

    题目来自老师的课后作业,如下所示.很多地方应该可以直接调用函数,但是初学Python,对里面的函数还不是很了解,顺便带着学习的态度,尽量自己动手code. 测试版代码,里面带有很多注释和测试代码: # ...

  9. QtQuick桌面应用程序开发指南 4)动态管理Note对象_B 5)加强外观 6)许多其他的改进

    4.2.2 Stateless(不管状态)JavaScript库 为了让开发轻松点, 使用一个JavaScript接口来和数据库交互是个好主意, 它在QML中提供了方便的方法; 在QtCreator中 ...

  10. dapper支持oracle游标

    dapper支持oracle游标 Dapper是一个轻型的ORM类.它有啥优点.缺点相信很多朋友都知道了,园里也有很多朋友都有相关介绍,这里就不多废话. 如果玩过Oracle都知道,存储过程基本都是通 ...