https://vjudge.net/problem/UVA-10652

给出n个长方形,用一个面积尽量小的凸多边形把他们围起来

求木板占包装面积的百分比

输入给出长方形的中心坐标,长,宽,以及长方形顺时针旋转的角度

求凸包

处理输入:

长方形四个顶点的向量坐标=中心点的向量坐标+从中心出发的向量旋转长方形的旋转角度

#include<cstdio>
#include<cmath>
#include<algorithm> using namespace std; const double pi=acos(-); const double eps=1e-; int dcmp(double x,double y)
{
if(fabs(x-y)<eps) return ;
return x<y ? - : ;
} struct Point
{
double x,y; Point(double x=,double y=):x(x),y(y) { } }; typedef Point Vector; Point P[],ch[]; 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 torad(double j)
{
return j*pi/;
} 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));
} bool cmp(Point A,Point B)
{ if(!dcmp(A.x,B.x)) return A.y<B.y;
return A.x<B.x;
} int ConvexHull(Point *p,int n,Point *c)
{
sort(p,p+n,cmp);
int m=;
for(int i=;i<n;++i)
{
while(m> && Cross(c[m-]-c[m-],P[i]-c[m-])<=)
m--;
c[m++]=P[i];
}
int k=m;
for(int i=n-;i>=;--i)
{
while(m>k && Cross(c[m-]-c[m-],P[i]-c[m-])<=) m--;
c[m++]=P[i];
}
if(n>) m--;
return m;
} double PolygonArea(Point *p,int n)
{
double area=;
for(int i=;i<n-;++i) area+=Cross(p[i]-p[],p[i+]-p[]);
return area/;
} int main()
{
int T,n,m,pc;
double x,y,w,h,j,ang;
double area1,area2;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
pc=;
area1=;
for(int i=;i<=n;++i)
{
scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j);
Point o(x,y);
ang=-torad(j);
P[pc++]=o+Rotate(Vector(-w/,-h/),ang);
P[pc++]=o+Rotate(Vector(-w/,h/),ang);
P[pc++]=o+Rotate(Vector(w/,-h/),ang);
P[pc++]=o+Rotate(Vector(w/,h/),ang);
area1+=w*h;
}
m=ConvexHull(P,pc,ch);
area2=PolygonArea(ch,m);
printf("%.1lf %%\n",area1*/area2);
}
}

uva 10625 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(凸包)

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

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

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

  5. uva 10652 Board Wrapping

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

  6. UVA 10652 Board Wrapping(凸包)

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

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

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

  8. ●UVA 10652 Board Wrapping

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

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

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

随机推荐

  1. startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI

    原代码如下: Intent intent = new Intent(); intent.setClass(mContext, PhotoView.class); Bundle bundle = new ...

  2. jstree API

    https://www.jstree.com/ drag & drop support(拖放)  keyboard navigation(键盘导航)  inline edit, create ...

  3. 如何在Windows Server 2003搭建Windows+iis+asp+access环境

    前提系统盘镜像要加载进来方案一:开始->管理您的服务器->添加或删除角色->下一步->自定义配置->下一步->选择应用程序服务器(IIS,ASP.NET)-> ...

  4. Windows中的键盘快捷方式

    Windows 中的键盘快捷方式 适用于: Windows 10Windows 8.1Windows 7 Windows 10 键盘快捷方式就是按键或按键组合,可提供一种替代方式来执行通常使用鼠标执行 ...

  5. 【GAN与NLP】GAN的原理 —— 与VAE对比及JS散度出发

    0. introduction GAN模型最早由Ian Goodfellow et al于2014年提出,之后主要用于signal processing和natural document proces ...

  6. Invalid AABB inAABB UnityEngine.Canvas:SendWillRenderCanvases()的解决办法

    我遇到这个问题的情况是, 在Start()中直接使用WWW价值本地图片,可能是加载图片相对比较耗时,就出现了这个错误. 解决的办法是使用协程: // Use this for initializati ...

  7. BigDecimal的setScale()方法无效(坑)

    最近在使用BigDecimal进行四舍五入时,发现setScale()方法设置的精度值并没有起作用,一度让我怀疑起是否jdk有bug,代码如下: 错误代码 double d = 7.199999999 ...

  8. 【Alpha】第五次Scrum meeting

    今日重大事件一览: 姓名 今日完成任务 所耗时间 刘乾 今日没有完成那个Issue..TuT第一次这么努力工作的我没有完成任务...真的是任务太坑啦. 任务完成了 60% Issue链接:https: ...

  9. 20135202闫佳歆--week4 课本第5章学习笔记

    第五章 系统调用 一.与内核通信 系统调用在用户控件进程和硬件设备之间添加了一个中间层,作用如下" 为用户空间提供了一种硬件的抽象接口 系统调用保证了系统的稳定和安全 每个进程都运行在虚拟系 ...

  10. 20170929php

    这是之前学习PHP类使用的代码 <?phpclass animal{ var $name="1"; var $sex="2"; public static ...