【旋转卡壳+凸包】BZOJ1185:[HNOI2007]最小矩形覆盖
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]最小矩形覆盖的更多相关文章
- BZOJ1185[HNOI2007] 最小矩形覆盖(旋转卡壳)
BZOJ1185[HNOI2007] 最小矩形覆盖 题面 给定一些点的坐标,要求求能够覆盖所有点的最小面积的矩形,输出所求矩形的面积和四个顶点的坐标 分析 首先可以先求凸包,因为覆盖了凸包上的顶点,凸 ...
- bzoj1185 [HNOI2007]最小矩形覆盖 旋转卡壳求凸包
[HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2081 Solved: 920 ...
- 2018.10.18 bzoj1185: [HNOI2007]最小矩形覆盖(旋转卡壳)
传送门 不难看出最后的矩形一定有一条边与凸包某条边重合. 因此先求出凸包,然后旋转卡壳求出当前最小矩形面积更新答案. 代码: #include<bits/stdc++.h> #define ...
- BZOJ1185 [HNOI2007]最小矩形覆盖 【旋转卡壳】
题目链接 BZOJ1185 题解 最小矩形一定有一条边在凸包上,枚举这条边,然后旋转卡壳维护另外三个端点即可 计算几何细节极多 维护另外三个端点尽量不在这条边上,意味着左端点尽量靠后,右端点尽量靠前, ...
- BZOJ1185 HNOI2007 最小矩形覆盖 凸包、旋转卡壳
传送门 首先,肯定只有凸包上的点会限制这个矩形,所以建立凸包. 然后可以知道,矩形上一定有一条边与凸包上的边重合,否则可以转一下使得它重合,答案会更小. 于是沿着凸包枚举这一条边,通过旋转卡壳找到离这 ...
- [BZOJ1185][HNOI2007]最小矩形覆盖-[凸包+旋转卡壳]
Description 传送门 Solution 感性理解一下,最小矩形一定是由一条边和凸包上的边重合的. 然后它就是模板题了..然而真的好难调,小于大于动不动就打错. Code #include&l ...
- BZOJ1185 : [HNOI2007]最小矩形覆盖
求出凸包后,矩形的一条边一定与凸包的某条边重合. 枚举每条边,求出离它最远的点和离它最左最右的点,因为那三个点是单调变化的,所以复杂度为$O(n)$. 注意精度. #include<cstdio ...
- bzoj千题计划209:bzoj1185: [HNOI2007]最小矩形覆盖
http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解去看它 http://www.cnblogs.com/TheRoadToTheGold/p ...
- 【BZOJ1185】[HNOI2007]最小矩形覆盖(凸包,旋转卡壳)
[BZOJ1185][HNOI2007]最小矩形覆盖(凸包,旋转卡壳) 题面 BZOJ 洛谷 题解 最小的矩形一定存在一条边在凸包上,那么枚举这条边,我们还差三个点,即距离当前边的最远点,以及做这条边 ...
随机推荐
- 4、libgdx应用框架
(原文:http://www.libgdx.cn/topic/29/4-libgdx%E5%BA%94%E7%94%A8%E6%A1%86%E6%9E%B6) 模块 作为核心.libgdx提供了六个接 ...
- Oracle查看对象空间使用情况show_space
tom大神写了一个用于查看Oracle数据库对象空间使用情况. 以下演示一下怎样使用: –工具源代码 CREATE OR REPLACE PROCEDURE show_space(p_segname ...
- 在应用中更新App版本号
在应用中, 为了提高用户体验, 会提供更新版本号的功能. 那么怎样实现呢? 我写了一个简单的Demo, 说明一下, 须要注意几个细节. 使用了Retrofit和Rx处理网络请求. Github下载地址 ...
- 通过案例学习 Secret - 每天5分钟玩转 Docker 容器技术(110)
在下面的例子中,我们会部署一个 WordPress 应用,WordPress 是流行的开源博客系统. 我们将创建一个 MySQL service,将密码保存到 secret 中.我们还会创建一个 Wo ...
- thinkphp5URL和路由
前面的话 本文将详细介绍thinkphp5URL和路由 URL访问 ThinkPHP采用单一入口模式访问应用,对应用的所有请求都定向到应用的入口文件,系统会从URL参数中解析当前请求的模块.控制器和操 ...
- JSR系列开篇
JSR是Java Specification Requests的缩写,意思是Java 规范提案.是指向JCP(Java Community Process)提出新增一个标准化技术规范的正式请求.任何人 ...
- JAVA提高二十:CopyOnWriteArrayList&CopyOnWriteArraySet&ConcurrentHashMap介绍
前面我们将java集合类的大部分类都进行了深入分析,但我们会发现一个共性问题就是并发的问题,那么如何解决呢?我们前面基本都是通过Collections的一个工具类来进行的解决,但实际大部分使用中人们普 ...
- 关于postgres中的一些宏的tips
Postgresql作为C语言开发的代码,其中大量的运用了一些宏的操作. 因此理解这些宏很重要,然而有时候这些宏总让人很费解. 作为一个经常翻翻postgresql源码的小白,在这里做一个记录吧,方便 ...
- iOS实现类似QQ的好友列表,自由展开折叠(在原来TableView的基础上添加一个字典,一个Button)
//直接代码 只包含 折叠展开字典的处理搭建#import "CFViewController.h" @interface CFViewController ()<UITab ...
- 7 Series GTP IP核使用总结 IP核配置篇
FPGA内嵌收发器相当于以太网中的PHY芯片,但更灵活更高效,线速率也在随着FPGA芯片的发展升级.本文对7系列FPGA内部高速收发器GTP IP核的配置和使用做些简单的总结,以备后续回顾重用.本文是 ...