博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5251 矩形面积(二维凸包旋转卡壳最小矩形覆盖问题) --2015年百度之星程序设计大赛 - 初赛(1)...
阅读量:4673 次
发布时间:2019-06-09

本文共 1507 字,大约阅读时间需要 5 分钟。

 
题意:给出n个矩形,求能覆盖所有矩形的最小的矩形的面积。
题解:对所有点求凸包,然后旋转卡壳,对没一条边求该边的最左最右和最上的三个点。
   利用叉积面积求高,利用点积的性质求最左右点和长度,更新面积最小值即可。
#include
#include
#include
#include
#define MAX 50010using namespace std;struct Point{ double x,y; Point(double x=0,double y=0):x(x),y(y){}};Point P[MAX],ch[MAX];typedef Point Vector;typedef Point point;Vector operator - (Point A,Point B){ return Vector(A.x-B.x,A.y-B.y);}bool operator <(const Point &a,const Point &b){ return a.x
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;}double Length(Vector A){ return dot(A,A);}double rotating_calipers(Point *p,int n){ int l=1,r=1,w; double ans=1e30; p[n]=p[0]; for(int i=0;i
=0) //因为边平行的时候面积相等 虽然如此但还是要继续找下一个 横着爬不动的意思 w=(w+1)%n; //找到最右的点 不可能向左的 while(dcmp(dot(p[i+1]-p[i],p[r+1]-p[i])-dot(p[i+1]-p[i],p[r]-p[i]))>0) //凸包不可能凹进去 所以不需要等号 加深对凸包求解过程的理解 r=(r+1)%n; if(i==0) l=r; while(dcmp(dot(p[i+1]-p[i],p[l+1]-p[i])-dot(p[i+1]-p[i],p[l]-p[i]))<=0) //必须加等号 否则凸包遇到直边的时候拐不过来 上不去 第二组样例可以完美说明问题 l=(l+1)%n; double d=Length(p[i+1]-p[i]); double area=fabs(Cross(p[i+1]-p[i],p[w]-p[i])) *fabs(dot(p[i+1]-p[i],p[r]-p[i])-dot(p[i+1]-p[i],p[l]-p[i]))/d; //cout<
<<" "; 这里灵活运用点积求底边长度 上面那一整行化简后就是底边长度 //cout<<"rrrrr "<
<<" lll "<
<

 分析过程:

转载于:https://www.cnblogs.com/Ritchie/p/5510345.html

你可能感兴趣的文章
[Algorithm] Find first missing positive integer
查看>>
[Angular] @ViewChild and template #refs to get Element Ref
查看>>
[Angular] Show a loading indicator in Angular using *ngIf/else, the as keyword and the async pipe
查看>>
[Angular] Configurable Angular Components - Content Projection and Input Templates
查看>>
[PWA] 17. Cache the photo
查看>>
[RxJS] ReplaySubject with buffer
查看>>
[Firebase] 3. Firebase Simple Login Form
查看>>
AI 线性代数
查看>>
ltp-ddt realtime_cpu_load涉及的cyclictest 交叉编译
查看>>
MySQL中Checkpoint技术
查看>>
【MT】牛津的MT教程
查看>>
Meta标签中的format-detection属性及含义
查看>>
PowerDesigner教程系列(四)概念数据模型
查看>>
DataGradView操作之,列头右键菜单隐藏和显示字段功能
查看>>
windows中使用Git工具连接GitHub(配置篇)
查看>>
示例 - 10行代码在C#中获取页面元素布局信息
查看>>
Linux 发行版本简介 (zz)
查看>>
POJ 2387 Til the Cows Come Home(Dijkstra)
查看>>
关于使用Tomcat服务器出现413错误的解决办法(Request Entity Too Large)
查看>>
离线使用iPhone SDK文档的方法
查看>>