【旋转卡壳+凸包】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 洛谷 题解 最小的矩形一定存在一条边在凸包上,那么枚举这条边,我们还差三个点,即距离当前边的最远点,以及做这条边 ...
随机推荐
- 腾讯qq等级计算公式面试题
就三道题大概是: 1. 推算出等级相应的天数 这个还比較简单,公式是:(b=2a+3) a是等级, b是相应的天数 2. 推算出等级总共的天数 先看下规律 等级a 相应天数b 总天数s 1 5 5 ...
- Android安全专项-利用androguard分析微信
androguard Androguard经常使用API学习1 安装 做 Android 安全測试之前你应该知道的工具 (一) 分析 ./androlyze.py -s进入分析的交互界面 然后运行 a ...
- 11g使用非duplicate方式创建物理standby要注意的问题总结
在上篇博文中,使用了duplicate方式来创建物理standby http://blog.csdn.net/aaron8219/article/details/38434579 今天来说说在11g中 ...
- canvas雪花
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ResourceBundle读取文件学习
开发中,我们经常需要读取本地文件(properties文件),这样的好处是文件是动态的,可配置的.这时候我们就需要用到ResourceBundle这个类. 这个类属于java.util.*. 这个类的 ...
- 你懂AI吗(1)
那场载入史册的战争之后,AI成为地球的主人已经快一个世纪了. 随着见证这场战争的那一代人基本消失,除了几个要堵上人类的尊严,颠覆AI的邪恶统治的组织外,现在的人基本已经习惯了这个AI统治的世界. AI ...
- Chef 自动化运维:Chef 的安装
安装准备 准备三台服务器,分别用作 Chef Server.Chef DK.Chef Client 的安装使用. 在三台服务器中,添加以下 hosts: vim /etc/hosts 192.168. ...
- .net 图片无损压缩
命名空间: using System.Drawing.Imaging; using System.Drawing; using System.Drawing.Drawing2D; #region Ge ...
- dubbo+zookeeper+jsp+springmvc+spring+mybatis+mysql+maven完整示例
项目分为三部分,这里分为三个maven项目(基于web,所以最后一个为maven创建的web项目) 1.接口定义以及实体类定义(api+pojo) --- maven创建java项目,打包成jar 2 ...
- 浅谈Unix I/O模型
关于I/O模型的文章比较多,参考多篇后理解上仍然不太满意,终需自己整理一次,也是编写高吞吐量高性能网络接口模块的基础.这里所说的主要针对网络I/O,近几年面对越来越大的用户请求量,如何优化这些步骤直接 ...