1185: [HNOI2007]最小矩形覆盖

Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special Judge
Submit: 1945  Solved: 853
[Submit][Status][Discuss]

Description

题解

显然矩形一边一定在凸包一边上

旋转卡壳维护其他三条边经过的顶点

更新答案

这题1A欸嘿嘿

代码

//by 减维
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<bitset>
#include<set>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<ctime>
#include<algorithm>
#define LL long long
#define db double
#define inf 1<<30
#define maxn 50005
#define eps 1e-8
using namespace std; struct node{
db x,y;
}poi[maxn],sta[maxn],ans[]; int n,top;
db mn=100000000.00; bool cmp(node x,node y){if(x.x==y.x)return x.y<y.y;return x.x<y.x;}
bool cm2(node x,node y){if(x.x==y.x)return x.y>y.y;return x.x>y.x;}
node operator - (node x,node y){return (node){x.x-y.x,x.y-y.y};}
node operator + (node x,node y){return (node){x.x+y.x,x.y+y.y};}
node operator * (node x,db y){return (node){x.x*y,x.y*y};}
node operator * (db x,node y){return (node){x*y.x,x*y.y};}
db operator * (node x,node y){return x.x*y.y-x.y*y.x;}
db operator / (node x,node y){return x.x*y.x+x.y*y.y;}
bool operator == (node x,node y){return x.x==y.x&&x.y==y.y;}
bool operator > (node x,node y){if(x.y==y.y)return x.x>x.y;return x.y>y.y;}
db dis(node x,node y){return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));} void solve()
{
db ds,h,ll,rr;
int t=,l=,r=;
sta[]=sta[top];
for(int i=;i<top;++i)
{
ds=dis(sta[i],sta[i+]);
while((sta[i+]-sta[i])*(sta[t+]-sta[i])-(sta[i+]-sta[i])*(sta[t]-sta[i])>-eps)t=(t+)%top;
while((sta[i+]-sta[i])/(sta[r+]-sta[i])-(sta[i+]-sta[i])/(sta[r]-sta[i])>-eps)r=(r+)%top;
if(i==)l=r;
while((sta[i+]-sta[i])/(sta[l]-sta[i])-(sta[i+]-sta[i])/(sta[l+]-sta[i])>-eps)l=(l+)%top;
ll=(sta[i+]-sta[i])/(sta[l]-sta[i])/ds;
rr=(sta[i+]-sta[i])/(sta[r]-sta[i])/ds;
h=(sta[i+]-sta[i])*(sta[t]-sta[i])/ds;
if(mn>(rr-ll)*h){
mn=(rr-ll)*h;
ans[]=sta[i]+(sta[i+]-sta[i])*(rr/ds);
ans[]=ans[]+(sta[r]-ans[])*(h/dis(sta[r],ans[]));
ans[]=ans[]+(sta[t]-ans[])*((rr-ll)/dis(sta[t],ans[]));
ans[]=ans[]+(ans[]-ans[]);
}
}
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;++i)scanf("%lf%lf",&poi[i].x,&poi[i].y);
sort(poi+,poi+n+,cmp);
sta[++top]=poi[];sta[++top]=poi[];
for(int i=;i<=n;++i){
while((poi[i]-sta[top-])*(sta[top]-sta[top-])>-eps&&top>=)top--;
sta[++top]=poi[i];
}
sort(poi+,poi+n+,cm2);
int sa=top;
if(sta[top]==poi[])sta[++top]=poi[],sa--;
else sta[++top]=poi[],sta[++top]=poi[];
for(int i=;i<=n;++i){
while((poi[i]-sta[top-])*(sta[top]-sta[top-])>-eps&&top>sa)top--;
sta[++top]=poi[i];
}
top--;
solve();
printf("%.5lf\n",mn);
int fir=;
for(int i=;i<=;++i)if(ans[fir]>ans[i])fir=i;
for(int i=;i<=;++i)printf("%.5lf %.5lf\n",ans[(fir+i)%],ans[(fir+i)%]);
return ;
}

【旋转卡壳+凸包】BZOJ1185:[HNOI2007]最小矩形覆盖的更多相关文章

  1. BZOJ1185[HNOI2007] 最小矩形覆盖(旋转卡壳)

    BZOJ1185[HNOI2007] 最小矩形覆盖 题面 给定一些点的坐标,要求求能够覆盖所有点的最小面积的矩形,输出所求矩形的面积和四个顶点的坐标 分析 首先可以先求凸包,因为覆盖了凸包上的顶点,凸 ...

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

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

  3. 2018.10.18 bzoj1185: [HNOI2007]最小矩形覆盖(旋转卡壳)

    传送门 不难看出最后的矩形一定有一条边与凸包某条边重合. 因此先求出凸包,然后旋转卡壳求出当前最小矩形面积更新答案. 代码: #include<bits/stdc++.h> #define ...

  4. BZOJ1185 [HNOI2007]最小矩形覆盖 【旋转卡壳】

    题目链接 BZOJ1185 题解 最小矩形一定有一条边在凸包上,枚举这条边,然后旋转卡壳维护另外三个端点即可 计算几何细节极多 维护另外三个端点尽量不在这条边上,意味着左端点尽量靠后,右端点尽量靠前, ...

  5. BZOJ1185 HNOI2007 最小矩形覆盖 凸包、旋转卡壳

    传送门 首先,肯定只有凸包上的点会限制这个矩形,所以建立凸包. 然后可以知道,矩形上一定有一条边与凸包上的边重合,否则可以转一下使得它重合,答案会更小. 于是沿着凸包枚举这一条边,通过旋转卡壳找到离这 ...

  6. [BZOJ1185][HNOI2007]最小矩形覆盖-[凸包+旋转卡壳]

    Description 传送门 Solution 感性理解一下,最小矩形一定是由一条边和凸包上的边重合的. 然后它就是模板题了..然而真的好难调,小于大于动不动就打错. Code #include&l ...

  7. BZOJ1185 : [HNOI2007]最小矩形覆盖

    求出凸包后,矩形的一条边一定与凸包的某条边重合. 枚举每条边,求出离它最远的点和离它最左最右的点,因为那三个点是单调变化的,所以复杂度为$O(n)$. 注意精度. #include<cstdio ...

  8. bzoj千题计划209:bzoj1185: [HNOI2007]最小矩形覆盖

    http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解去看它 http://www.cnblogs.com/TheRoadToTheGold/p ...

  9. 【BZOJ1185】[HNOI2007]最小矩形覆盖(凸包,旋转卡壳)

    [BZOJ1185][HNOI2007]最小矩形覆盖(凸包,旋转卡壳) 题面 BZOJ 洛谷 题解 最小的矩形一定存在一条边在凸包上,那么枚举这条边,我们还差三个点,即距离当前边的最远点,以及做这条边 ...

随机推荐

  1. url特殊字符转义及解决方法

    URL特殊字符需转义 1.空格换成加号(+) 2.正斜杠(/)分隔目录和子目录 3.问号(?)分隔URL和查询 4.百分号(%)制定特殊字符 5.#号指定书签 6.&号分隔参数 转义字符的原因 ...

  2. Softmax多分类算法

    List<double[]> inputs_x = new List<double[]>(); inputs_x.Add(new double[] { 0.2, 0.3 }); ...

  3. 浅析JavaScript的字符串查找函数:indexOf和search

    语法 ①indexOf:方法可返回某个指定的字符串值在长字符串中首次出现的位置.如果被查找字符串没有找到,返回-1. indexOf 说明:该方法将从头到尾地检索字符串 stringObject,看它 ...

  4. 理解spread运算符与rest参数

    理解spread运算符与rest参数 spread运算符与rest参数 是ES6的新语法.它们的作用是什么?能做什么事情? 1. rest运算符用于获取函数调用时传入的参数. function tes ...

  5. DotNetCore跨平台~功能测试TestHost的使用

    回到目录 之前写了关于自动化测试的相关文章,包括gitlab,unittest,jenkins pipeline等,基于都是功能点的测试,当我们的框架或者业务修改之后,需要走一篇自动化测试,以此来保证 ...

  6. 【CSS3】背景

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. HTML基础教程-元素

    HTML 元素 HTML 文档是由 HTML 元素定义的. HTML 元素 HTML 元素指的是从开始标签(start tag)到结束标签(end tag)的所有代码. 注释:开始标签常被称为开放标签 ...

  8. 用html和css轻松实现康奈尔笔记(5R笔记)模板

    缘起 人家都说康奈尔笔记法,很好用呢,能抵抗遗忘曲线,让你的笔记事半功倍,有兴趣的同学自行百度哈. 网上有很多现成的模板,下载下来之后吧,看着好像在上面写英文可能更方便一点,行距很小,而且还有网址在上 ...

  9. Visual Studio Code 通过 Chrome插件Type Script断点调试Angular 2

    1. 下载Visual Studio Code (https://code.visualstudio.com/) 2. 安装插件Debugger for chrome 3. 确定tsconfig.js ...

  10. SLAM入门之视觉里程计(2):两视图对极约束 基础矩阵

    在上篇相机模型中介绍了图像的成像过程,场景中的三维点通过"小孔"映射到二维的图像平面,可以使用下面公式描述: \[ x = MX \]其中,\(c\)是图像中的像点,\(M\)是一 ...