bzoj 1185 [HNOI2007]最小矩形覆盖——旋转卡壳
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185
矩形一定贴着凸包的一条边。不过只是感觉这样。
枚举一条边,对面的点就是正常的旋转卡壳。两边的那个点可以用点积的最小/大来判断,因为是投影。
然后调了一万年。不过好像把精度设成 1e-13 而不是 1e-8 就能过了。
和许多代码对拍,有各种各样的不同。也不知道自己是不是真的对了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define db double
using namespace std;
const int N=5e4+;const db eps=1e-,INF=1e18;
int n,tot; db ans;
struct Node{
db x,y;
Node(db a=,db b=):x(a),y(b) {}
bool operator< (const Node &b)const {return x<b.x||(x==b.x&&y<b.y);}
Node operator- (const Node &b)const {return Node(x-b.x,y-b.y);}
Node operator+ (const Node &b)const {return Node(x+b.x,y+b.y);}
db operator* (const Node &b)const {return x*b.x+y*b.y;}
Node operator* (const db &b)const {return Node(x*b,y*b);}
Node operator/ (const db &b)const {return Node(x/b,y/b);}
}t[N],a[N],prn[];
db Mx(db a,db b){return a>b?a:b;}
int dcmp(db x){if(x>eps)return ;if(x<-eps)return -;return ;}
db cross(Node u,Node v){return u.x*v.y-u.y*v.x;}
void upd(int &x){x>n?x-=n:;}
db Sqr(db x){return x*x;}
db dist(Node u,Node v){return sqrt(Sqr(u.x-v.x)+Sqr(u.y-v.y));}
int main()
{
scanf("%d",&tot);
for(int i=;i<=tot;i++)scanf("%lf%lf",&t[i].x,&t[i].y);
sort(t+,t+tot+);
for(int i=;i<=tot;i++)
{while(n>&&dcmp(cross(a[n]-t[i],a[n-]-t[i]))>=)n--;a[++n]=t[i];}
for(int i=tot-,lm=n;i;i--)
{while(n>lm&&dcmp(cross(a[n]-t[i],a[n-]-t[i]))>=)n--;a[++n]=t[i];}
a[n]=a[]; n--; ans=INF;
int p0=,cr=,p1=;//out of for()
for(int i=;i<=n;i++)
{
Node d=a[i+]-a[i];
while(dcmp(cross(d,a[cr+]-a[i])-cross(d,a[cr]-a[i]))>)cr++,upd(cr);
while(dcmp((a[p0+]-a[i])*d-(a[p0]-a[i])*d)>=)p0++,upd(p0);//>=?
if(i==)p1=cr;//
while(dcmp((a[p1+]-a[i])*d-(a[p1]-a[i])*d)<=)p1++,upd(p1); db len=dist(a[i+],a[i]);
db s1=(a[p0]-a[i])*d/len, s2=(a[p1]-a[i])*d/len;
db hi=cross(d,a[cr]-a[i])/len, ara=(s1-s2)*hi;//not /(2*len)
if(dcmp(ara-ans)>=)continue; ans=ara;
// if(ara>=ans)continue; ans=ara;
Node x1=d/len*(s1-s2);
Node x2=d/len*hi; swap(x2.x,x2.y); x2.x=-x2.x;//*i
prn[]=a[i]+d/len*s2; prn[]=prn[]+x1;
prn[]=prn[]+x2; prn[]=prn[]+x2;
}
printf("%.5f\n",ans);int id=;
for(int i=;i<=;i++)
{
Node u=prn[i],v=prn[id];
if(dcmp(u.y-v.y)<||(!dcmp(u.y-v.y)&&dcmp(u.x-v.x)<))id=i;
}
for(int j=;j<=;j++,id++,id>?id=:)
{
if(!dcmp(prn[id].x))prn[id].x=;
if(!dcmp(prn[id].y))prn[id].y=;//avoid -0
printf("%.5f %.5f\n",prn[id].x,prn[id].y);
}
return ;
}
bzoj 1185 [HNOI2007]最小矩形覆盖——旋转卡壳的更多相关文章
- 洛谷 P3187 BZOJ 1185 [HNOI2007]最小矩形覆盖 (旋转卡壳)
题目链接: 洛谷 P3187 [HNOI2007]最小矩形覆盖 BZOJ 1185: [HNOI2007]最小矩形覆盖 Description 给定一些点的坐标,要求求能够覆盖所有点的最小面积的矩形, ...
- BZOJ 1185: [HNOI2007]最小矩形覆盖 [旋转卡壳]
1185: [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1435 Solve ...
- BZOJ 1185: [HNOI2007]最小矩形覆盖-旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标-备忘板子
来源:旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标 BZOJ又崩了,直接贴一下人家的代码. 代码: #include"stdio.h" #include"str ...
- BZOJ:1185: [HNOI2007]最小矩形覆盖
1185: [HNOI2007]最小矩形覆盖 这计算几何……果然很烦…… 发现自己不会旋转卡壳,补了下,然后发现求凸包也不会…… 凸包:找一个最左下的点,其他点按照与它连边的夹角排序,然后维护一个栈用 ...
- bzoj1185 [HNOI2007]最小矩形覆盖 旋转卡壳求凸包
[HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2081 Solved: 920 ...
- bzoj 1185 [HNOI2007]最小矩形覆盖 凸包+旋转卡壳
题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...
- BZOJ 1185 [HNOI2007]最小矩形覆盖:凸包 + 旋转卡壳
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 题意: 给出二维平面上的n个点,问你将所有点覆盖的最小矩形面积. 题解: 先找出凸 ...
- ●BZOJ 1185 [HNOI2007]最小矩形覆盖
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解: 计算几何,凸包,旋转卡壳 结论:矩形的某一条边在凸包的一条边所在的直线上. ( ...
- 【bzoj1185】[HNOI2007]最小矩形覆盖 (旋转卡壳)
给你一些点,让你用最小的矩形覆盖这些点 首先有一个结论,矩形的一条边一定在凸包上!!! 枚举凸包上的边 用旋转卡壳在凸包上找矩形另外三点... 注意精度问题 #include<cstdio> ...
随机推荐
- 我的 VSCode 常用扩展
Beautify (option+shift+F) Bookmarks (option+option+k,l,j) Debugger for Chrome Docker EditorConfig fo ...
- Git 常用命令和 Git Flow 梳理
git 用 git 有一段时间了,之前没有详细地了解 git flow,导致协作过程中或多或少出现了一些头疼问题.最近静下心来理了下 git flow 的整个流程,再回头看开朗了不少,总结到这里.介绍 ...
- 转:在Eclipse的Debug页签中设置虚拟机参数
http://blog.csdn.net/decorator2015/article/details/50914479 在Eclipse的Debug页签中设置虚拟机参数 步骤 1,Run->De ...
- js排序算法01——冒泡排序
在codewars上面刷题卡住刷不下去了,意识到自己算法方面的不足,准备写一些算法方面的文章,此为一. 冒泡排序是很常见简单的算法了,每次比较任何两个相邻的项,如果第一个比第二个大,则交换他们,就像气 ...
- shiro权限定义的三种方法
1.在配置文件中定义 <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFa ...
- 什么是web?什么是web服务器?什么是应用服务器?
1.什么是Web? 简单来说,Web就是在Http协议基础之上,利用浏览器进行访问的网站.目前来看最常用的意义是指在 Intenet 上和 HTML 相关的部分.换句话说,目前在 Intenet 上通 ...
- SpringXML方式配置bean的生存范围Scope
在一个bean的配置里面可以指定一个属性Scope,也就是bean的范围,bean的生命周期. Scope可取的值5种:singleton(默认).prototype.request.session. ...
- CentOS7 修改默认时区为 北京时间
首先同步时间 yum install -y ntpdate ntpdate -u cn.pool.ntp.org 然后设置中国时区(北京时间) timedatectl set-timezone Asi ...
- 20165202 2017-2018-2 《Java程序设计》第8周学习总结
20165202 2017-2018-2 <Java程序设计>第8周学习总结 教材学习内容总结 Ch12 进程与线程 线程是比进程更小的单位,一个进程在其执行过程中,可以产生多个线程 Ja ...
- L153
警言是指传达一般真理或某种言论的短小句子.An aphorism is a short witty sentence which expresses a general truth or commen ...