uva 10652 Board Wrapping

2024-03-24 08:38
文章标签 board wrapping uva 10652

本文主要是介绍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 %

中文:
给你一堆矩形,然后告诉你矩形的长宽,以及矩形的中心坐标,以及矩形绕着自身中心的旋转度数。让你把这些矩形用直线圈起来。最后问你这些矩形占你圈出来的面积的百分比。

#include <bits/stdc++.h>
#define Vector Point
using namespace std;
//fstream in,out;
const int maxn=2405;
const double PI=acos(-1);
double torad(double deg)
{return deg/180*PI;
}
struct Point
{double x,y;Point(double x=0,double y=0):x(x),y(y){}
};bool operator < (const Point &a,const Point &b)
{return a.x<b.x||(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);}
double Cross(Vector A,Vector B)
{return A.x*B.y-A.y*B.x;
}
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;
}
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 PolyonArea(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 main()
{ios::sync_with_stdio(false);int t,n;Point P[maxn],ch[maxn];cin>>t;while(t--){int pc=0;double x,y,w,h,j,ang,board,hull;board=hull=0;cin>>n;for(int i=0;i<n;i++){cin>>x>>y>>w>>h>>j;Point o(x,y);ang=-torad(j);P[pc++]=o+Rotate(Vector(-w/2,-h/2),ang);P[pc++]=o+Rotate(Vector(w/2,-h/2),ang);P[pc++]=o+Rotate(Vector(-w/2,h/2),ang);P[pc++]=o+Rotate(Vector(w/2,h/2),ang);board+=w*h;}int m=ConvexHull(P,pc,ch);hull=PolyonArea(ch,m);cout<<fixed<<setprecision(1)<<board*100/hull<<" %"<<endl;}return 0;
}

解答:
我的第一道凸包题目,这题就是裸题,代码来自刘汝佳的白书。很好的模板,凸包算法为andrew算法,非常好理解,自己在纸上画一画就能明白。

这篇关于uva 10652 Board Wrapping的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/841044

相关文章

UVA - 12206 Stammering Aliens (hash)

这题其实很容易想到2分长度,关键是2分后,怎么判断出现最多次的串是否》=m次了。这里需要用到hash来处理。 对于一个字符串   H[i] =H[i+1]*131+s[i]  ;其中 H[n]=0;那么对于一个长度为L的串 ,hanh[i,l]=H[i]-H[i+L]*x^L ; 这样记录每个字符串的hash值,然后再处理起来就比较简单了。 VIEW CODE #include<

[Uva 11990] Dynamic Inversion (CDQ分治入门)

Uva - 11990 动态逆序对,求删除一个点之前序列中逆序对的个数 首先倒过来看这个问题,把点先全部删掉 然后从最后一个点开始倒着往数列中加点 求加完这个点逆序对的变化 CDQ分治做法 把删除时间看作 t,下标看作 x,值看作 y 然后对 x排序,对 t偏序,用树状数组维护 y 具体来说就是对于每个点 (t0,x0,y0) (t_0, x_0, y_0) 先统计

UVA 11624 搜索

给出1000*1000矩阵,含起点‘J’,路‘.',墙‘#’,火‘F'; 火每秒蔓延一格,人每秒走一步 问人是否可以安全走出矩阵,不能被火碰到 先对所有火BFS一遍,记录每个点被烧到的时间 然后对人BFS一遍,若到每点前没被火烧即可走 #include "stdio.h"#include "string.h"#include "queue"using namespace

UVa 11361 Investigating Div-Sum Property

这道题居然提交了十次才过....期间小问题不断。思路的话基本是《训练指南》里面来的,不过有几个小问题需要注意一下。第一,当K在大于100的情况下,就直接输出0就可以了。因为a,b不超过2^31,可以估算出a,b最多十位十进制数,那么每位最大为9,所以各个数字之和是不可能超过100的,那么个数字之和为模K为0的条件是永远不可能到达的。       还有一点是,当剩余数字d=0时,当且

UVa 1362(LA 3516) Exploring Pyramids

依旧是《训练指南》上的一道例题。思路大致相同,即设有一个序列S(i),S(i+1),S(i+2)...S(j),d[i,j]为所求的解。当S(i)==S(k),i<k<=j 时,说明在k回到根,那么S(i+1)...S(k-1)构成一棵独立的子树(当然也可能并不是子树)。那么d[i,j]就要加上d[i+1,k-1]*d[k,j],不断递增k,每遇到一个k,d[i,j]+=d[i

UVa 11174 Stand in a Line

依旧是《训练指南》上的一道例题。书上讲的比较抽象,下面就把解法具体一下。因为涉及到父子关系,因此自然而然可以将n个节点构造成一棵树,最后将形成一个森林。接下来将使用递归的手法。设f(i)是以节点i为树根的子树,节点i有儿子c1,c2,c3....cj共j棵子树。s[i]为树根为i的子树包含的节点数。如果分别先给各个子树内部排序,那么毫无疑问, 共有f(c1)*f(c2)*f(c3).

UVa 11375 Matches

大年夜的写代码果然状态非常之差...感觉特别困,连个高精度都折腾了我好久。还是刘汝佳《训练指南》里的一道例题,解题思路其实也差不多,但是想对书里面的内容再讲讲。其中d[i]是代表i个火柴棒恰好能构成的正整数数目(不包含整数0),然后有点类似于动态规划的做法,通过已知的d[]求出剩下的d[]。        不过仔细想来貌似有点问题。例如已知d[j],那么d[j+num[0]]+=d[

UVa CD 0-1背包且打印路径

就是简单的0-1背包问题,不过没有具体的效益值,隐含的效益值就是剩余背包的容量。因为要输出具体选择了那些track(也就是物品),所以采用序偶的方法。其实0-1背包的解画在坐标轴上就是一个分段函数,所谓序偶就是那些跃迁的节点。但是这道题略有不同,第0阶段的初始序偶不是(0,0),而是(0,N)。序偶的第一个参数表示容量,第二个参数表示背包的剩余容量。当由前一阶段的序偶得到新序偶,并且

UVa 116 Unidirectional TSP

这道题是非常基础的动态规划,类似于分阶段决策。题意是:一个M*N的数组,要求从第1列走到第N列且下一步的位置都只能是当前位置的相邻右侧,相邻右上,相邻右下三个位置。要求路径上的格子内的数字和最小。若有和相同的路径,则输出字典序最小的那一条路径。解法其实就是设置一个记忆数组,分阶段决策即可。         但是决策有从左往右和从右往左两种方式。开始我使用的从左往右的方式,这稍微麻

UVA 103--- Stacking Boxes

这道题在小白书中的分类是动态规划,把题AC了之后在网上看解题报告后,多数解法也是DAG上的动态规划。但其实一个简单的深度优先就能解决问题了。首先将每数从大到小排序,再将各组按照排序后的第一个数字的大小进行从大到小排序。需要注意的是,记录各组数据的编号也要和数进行同步的排序。 #include <iostream>#include <cstdio>#include <vect