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. libgdx3D第三讲-场景载入

    第三讲 场景载入 Loading a scene with LibGDX 网易云地址:id=442771fd5cc6ce8cf9fd30b838a76343&type=note" s ...

  2. MyBatis_通过resultMap解决不一致的问题

  3. 自学Zabbix3.10.1.1-事件通知Notifications upon events-媒介类型email

    自学Zabbix3.10.1.1-事件通知Notifications upon events-媒介类型email 配置媒介Email Administration→Media types->Cl ...

  4. 快收藏!高手Linux运维管理必备工具大全,你会吗?

    一.统一账号管理 1.LDAP 统一管理各种平台帐号和密码,包括但不限于各种操作系统(Windows.Linux),Linux系统sudo集成,系统用户分组,主机登入限制等:可与Apache,HTTP ...

  5. python decorator 进阶

    上一篇文章开始的时候提到 “一般来说,装饰器是一个函数,接受一个函数(或者类)作为参数,返回值也是也是一个函数(或者参数)” 有一般情况,就有特殊情况.第一种特殊情况:装饰器可能也是一个类:第二种特殊 ...

  6. HTML:Event [转]

    这篇文章对于了解Javascript的事件处理机制非常好,将它全文转载于此,以备不时之需. 什么是事件? 事件(Event)是JavaScript应用跳动的心脏 ,也是把所有东西粘在一起的胶水.当我们 ...

  7. 前端MVC Vue2学习总结(二)——Vue的实例、生命周期与Vue脚手架(vue-cli)

    一.Vue的实例 1.1.创建一个 Vue 的实例 每个 Vue 应用都是通过 Vue 函数创建一个新的 Vue 实例开始的: var vm = new Vue({ // 选项 }) 虽然没有完全遵循 ...

  8. git 设置和取消代理

    # 设置ss git config --global http.proxy 'socks5://127.0.0.1:1080' git config --global https.proxy 'soc ...

  9. JS获取字符对应的ASCII码

    有时候会需要用到字符的ASCII码,一时之间调试时可能会忘记字符与ASCII码对应的数字. 最近喜欢用浏览器控制台直接跑JS代码,将这个代码直接贴到浏览器控制台,即可调试(谷歌浏览器快捷键 ctrl+ ...

  10. Xamarin使用ListView开启分组视图Cell数据展示bug处理

    问题描述 Xamarin使用IsGroupingEnabled="true"之后再Cell操作就会出现数据展示bug,数据不刷新的问题,如下图所示: 点击取消的是其他钢厂,但Vie ...