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

代码:

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. using namespace std;
  7. const double Pi=acos(-1.0);
  8. struct Point{
  9. double x,y;
  10. Point(double x=,double y=):x(x),y(y){}
  11. };
  12. typedef Point Vector;
  13. bool operator < (Point a,Point b){return a.x<b.x||(a.x==b.x&&a.y<b.y);}
  14. Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
  15. double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
  16. double Length(Vector a){return sqrt(Dot(a,a));}
  17. double Angle(Vector a,Vector b){return acos(Dot(a,b)/Length(a)/Length(b));}
  18. Vector Rotate(Vector a,double rad){return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));}
  19. double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
  20. Point operator + (Point a,Vector b){return Point(a.x+b.x,a.y+b.y);}
  21. Point getdot(Point a,Vector b,double ang){return a+Rotate(b,ang);}
  22. double getrad(double ang){return Pi*(ang/);}
  23. Point ans[],at[];
  24. int nu;
  25. double polygonArea(){
  26. int k=;
  27. for(int i=;i<nu;i++){
  28. while(k>&&Cross(ans[k-]-ans[k-],at[i]-ans[k-])<=)k--;
  29. ans[k++]=at[i];
  30. }
  31. int p=k;
  32. for(int i=nu-;i>=;i--){
  33. while(k>p&&Cross(ans[k-]-ans[k-],at[i]-ans[k-])<=)k--;
  34. ans[k++]=at[i];
  35. }
  36. double x=;
  37. k--;
  38. if(k<)return ;
  39. for(int i=;i<k-;i++)x+=Cross(ans[i]-ans[],ans[i+]-ans[]);
  40. return x/;
  41. }
  42. int main(){
  43. int T,n;
  44. double x,y,w,h,ang;
  45. scanf("%d",&T);
  46. while(T--){
  47. double area1=,area2=;
  48. nu=;
  49. scanf("%d",&n);
  50. while(n--){
  51. scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&ang);
  52. area2+=w*h;
  53. Point a;
  54. ang=-getrad(ang);//因为是顺时针旋转的,所以要是负的。。。。。
  55. at[nu++]=getdot(Point(x,y),Vector(w/,h/),ang);
  56. at[nu++]=getdot(Point(x,y),Vector(-w/,h/),ang);
  57. at[nu++]=getdot(Point(x,y),Vector(w/,-h/),ang);
  58. at[nu++]=getdot(Point(x,y),Vector(-w/,-h/),ang);
  59. }
  60. sort(at,at+nu);
  61. area1=polygonArea();
  62. // printf("%lf %lf\n",area1,area2);
  63. printf("%.1lf %%\n",*area2/area1);
  64. }
  65. return ;
  66. }

UVA 10652 Board Wrapping(凸包)的更多相关文章

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

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

  2. UVA 10652 Board Wrapping 计算几何

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

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

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

  4. UVA 10652 Board Wrapping(凸包)

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

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

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

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

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

  7. uva 10652 Board Wrapping

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

  8. ●UVA 10652 Board Wrapping

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

  9. uva 10625 Board Wrapping

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

随机推荐

  1. 【踩坑】近来在Firefox上遇到的一些坑

    因为工作一年多以来,做的工作基本都是和webkit系列打交道. 先是做m站,后来做了两个app内嵌的hybrid项目,从来只考虑webkit前缀和相关的伪类. 最近四个多月开始做内部的管理系统,写写样 ...

  2. zoj 3714 Java Beans

    /*很简单的一题,求连续的m位,求总和最多的值,循环找一下,就出来了*/ #include<stdio.h> ]; int main(int argc, char* argv[]) { i ...

  3. js页面跳转 和 js打开新窗口 方法

    js页面跳转 和 js打开新窗口 方法 第一种: 第二种: 第三种: 第四种: 第五种: 1.在原来的窗体中直接跳转用 window.location.href="你所要跳转的页面" ...

  4. Spring注解与Spring与Struts2整合

    @Component @Controller @Service @Repository 四大注解作用基本一样,只是表象在不同层面 @Resource @Scope Struts2与Spring整合:1 ...

  5. Nmon的安装及使用

    1.安装软件 1) 用root用户登录系统,建立目录:#mkdir  /nmon 2) 通过FTP将下载的nmon工具上传至服务器 192.168.40.212目录/nmon下. 3) 修改tar包权 ...

  6. IOS 页面之间的传值(主讲delegate)

    IOS的Delegate,通俗一点说就是页面之间的传值. 总结一下现在知道的IOS页面之间传值的方式有三种 1.使用NSNotification发送通知的传值 主要是通过NSNotificationC ...

  7. First AngularJS !

    My first angular! <html ng-app> <head> <meta charset="utf-8"> <script ...

  8. Win32 SecuritySetting

    http://flylib.com/books/en/2.21.1.207/1/ http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/ ...

  9. golang ODBC 访问access数据库(问题解决之心理路程)

    最近项目需要,需要操作access,以前是用VC++ OLE访问,网络用ACE库,感觉很庞大...决定用go试试 网上用的最多的就是这个https://github.com/weigj/go-odbc ...

  10. [转]chrome技术文档列表

    chrome窗口焦点管理系统 http://www.douban.com/note/32607279/ chrome之TabContents http://www.douban.com/note/32 ...