题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185

枚举一条边,维护上、左、右方的点;

上方点到这条边距离最远,所以用叉积求面积维护;

左右点到这条边的射影最长(!),所以用点积求射影维护;

因为维护的点是只能逆时针走的,所以初始的左边点要特殊处理一下,其实等于右边点即可,然后可以走过去到合适位置;

然后维护矩形的四个端点,就是根据距离,从边的端点走过去,还挺有意思的;

注意不要输出 -0;

然而这其实是假的呵呵,Narh 一拍就出错了,还是很小的数据很明显的错囧

只是不知道哪里错,怎么调...

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef double db;
db const eps=1e-;
int const xn=;
int n;
db ans;
int dmp(db x){if(fabs(x)<=eps)return ; return x>eps?:-;}
struct P{
db x,y;
P(db x=,db y=):x(x),y(y) {}
bool operator < (const P &b) const
{return dmp(x-b.x)<||dmp(x-b.x)==&&dmp(y-b.y)<;}
P operator + (const P &b) const
{return P(x+b.x,y+b.y);}
P operator - (const P &b) const
{return P(x-b.x,y-b.y);}
P operator * (const db &v) const
{return P(x*v,y*v);}
P operator / (const db &v) const
{return P(x/v,y/v);}
}p[xn],c[xn],pos[];
db cross(P a,P b){return a.x*b.y-a.y*b.x;}
db dot(P a,P b){return a.x*b.x+a.y*b.y;}
void find()
{
sort(p+,p+n+); int top=;
for(int i=;i<=n;i++)
{
while(top>&&dmp(cross(c[top]-c[top-],p[i]-c[top]))<=)top--;
c[++top]=p[i];
}
int num=top;
for(int i=n-;i;i--)
{
while(top>num&&dmp(cross(c[top]-c[top-],p[i]-c[top]))<=)top--;
c[++top]=p[i];
}
n=top-;
}
int upt(int x){if(x>n)x-=n; if(x<)x+=n; return x;}
db sqr(db x){return x*x;}
db dis(P a,P b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
bool cmp(P a,P b){return dmp(a.y-b.y)<||(dmp(a.y-b.y)==&&dmp(a.x-b.x)<);}
void rc()
{
ans=-;
//int p=2,l=1,r=2;//
int p=,l=,r=; c[n+]=c[];
for(int i=;i<=n;i++)
{
db d=dis(c[i],c[i+]);
while(dmp(cross(c[i]-c[p],c[i+]-c[p])-cross(c[i]-c[p+],c[i+]-c[p+]))<=)p=upt(p+);
while(dmp(dot(c[r]-c[i],c[i+]-c[i])-dot(c[r+]-c[i],c[i+]-c[i]))<=)r=upt(r+);
if(i==)l=r;//
while(dmp(dot(c[l]-c[i],c[i+]-c[i])-dot(c[l+]-c[i],c[i+]-c[i]))>=)l=upt(l+);
db L=dot(c[i+]-c[i],c[l]-c[i])/d;
db R=dot(c[i+]-c[i],c[r]-c[i])/d;
db H=cross(c[i]-c[p],c[i+]-c[p])/d;
db tmp=(R-L)*H;
if(ans<||dmp(ans-tmp)>)
{
ans=tmp;
pos[]=c[i]+(c[i+]-c[i])*(R/d);
pos[]=pos[]+(c[r]-pos[])*(H/dis(c[r],pos[]));
//pos[2]=pos[1]+(c[p]-pos[1])*((R-L)/dis(c[p],pos[1]));//也可
pos[]=pos[]+(c[i]-pos[])*((R-L)/dis(c[i],pos[]));
pos[]=pos[]+(pos[]-pos[]);
}
}
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
find();
rc();
printf("%.5f\n",ans);
int st=;
for(int i=;i<;i++)if(cmp(pos[i],pos[st]))st=i;
for(int i=st,cnt=;cnt<=;i=(i+)%,cnt++)
{
if(fabs(pos[i].x)<=eps)pos[i].x=;
if(fabs(pos[i].y)<=eps)pos[i].y=;
printf("%.5f %.5f\n",pos[i].x,pos[i].y);
}
return ;
}

bzoj 1185 最小矩形覆盖 —— 旋转卡壳的更多相关文章

  1. 洛谷 P3187 BZOJ 1185 [HNOI2007]最小矩形覆盖 (旋转卡壳)

    题目链接: 洛谷 P3187 [HNOI2007]最小矩形覆盖 BZOJ 1185: [HNOI2007]最小矩形覆盖 Description 给定一些点的坐标,要求求能够覆盖所有点的最小面积的矩形, ...

  2. BZOJ 1185: [HNOI2007]最小矩形覆盖 [旋转卡壳]

    1185: [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1435  Solve ...

  3. bzoj1185 [HNOI2007]最小矩形覆盖 旋转卡壳求凸包

    [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2081  Solved: 920 ...

  4. bzoj 1185 [HNOI2007]最小矩形覆盖——旋转卡壳

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 矩形一定贴着凸包的一条边.不过只是感觉这样. 枚举一条边,对面的点就是正常的旋转卡壳. ...

  5. BZOJ 1185: [HNOI2007]最小矩形覆盖-旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标-备忘板子

    来源:旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标 BZOJ又崩了,直接贴一下人家的代码. 代码: #include"stdio.h" #include"str ...

  6. 【bzoj1185】[HNOI2007]最小矩形覆盖 (旋转卡壳)

    给你一些点,让你用最小的矩形覆盖这些点 首先有一个结论,矩形的一条边一定在凸包上!!! 枚举凸包上的边 用旋转卡壳在凸包上找矩形另外三点... 注意精度问题 #include<cstdio> ...

  7. BZOJ 1185 最小矩形覆盖

    Description Input Output Sample Input Sample Output HINT 其实这题就是一道旋转卡壳的裸题,但是我的精度萎了.直接上hzwer的代码吧... #i ...

  8. HDU 5251 矩形面积 (旋转卡壳)

    2015年百度之星程序设计大赛 - 初赛(1) 1006 比赛链接:2015年百度之星程序设计大赛 - 初赛(1) 题目链接:HDU 5251 Problem Description 小度熊有一个桌面 ...

  9. bzoj 1185 [HNOI2007]最小矩形覆盖 凸包+旋转卡壳

    题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...

随机推荐

  1. [ArcGIS]Oracle RAC下创建地理数据库(Create Enterprise Geodatabase)失败的解决方法

    转载请注明原文地址:http://www.cnblogs.com/litou/p/8028843.html 环境:Oracle 11g 11.2.0.1.0(双节点RAC群集),ArcGIS Desk ...

  2. cocos2dx使用cocostudio导出的animation

    local uilocal function createLayerUI() if not ui then ui=cc.Layer:create(); createLayerUI=nil; end r ...

  3. [note]BSGS & exBSGS

    BSGS (感觉这东西还是要写一下) BSGS主要用于求解形如\(x^k=y\pmod p\)(注意这里p与x互质)这样的方程的最小正整数解的问题 设\(m=\lceil\sqrt p\rceil,k ...

  4. struts自定义拦截器实现

    示例 添加新功能:只有是登录的状态访问hello_loginSuccess才会显示登录成功. index.jsp登录成功页面 test.jsp登录页面 一.修改原代码实现 1.登录后将登录信息添加到S ...

  5. awk 字符串函数

    awk 提供了许多强大的字符串函数,见下表: awk 内置字符串函数 gsub(r,s) 在整个 $0 中用 s 替代 r gsub(r,s,t) 在整个 t 中用 s 替代 r index(s,t) ...

  6. FOXMAIL提示容量满无法收邮件,清除旧邮件后还是无法收取,请问如何解决?

    FOXMAIL提示容量满无法收邮件,清除旧邮件后还是无法收取,请问如何解决? 2009-03-23 11:21包子燕  分类:网站使用 我清除了FOXMAIL所在的磁盘空间,共有12G,也删除了部分旧 ...

  7. Data Structure Graph: prim

    最小生成树算法.这里的s是可以随意选取的,不影响树的生成,但是不同的s有不同的dis #include <iostream> #include <vector> #includ ...

  8. [转]详解Java解析XML的四种方法

    XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便.对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM ...

  9. HDU2544最短路模板,

    #include<iostream> #include<stdio.h> #include<stdlib.h> #include<algorithm> ...

  10. CodeForces 455C Civilization(并查集+树直径)

    好久没有写过图论的东西了,居然双向边要开两倍空间都忘了,不过数组越界cf居然给我报MLE??这个题题意特别纠结,一开始一直不懂添加的边长是多长... 题意:给你一些点,然后给一些边,注意没有重边 环, ...