传送门

不难看出最后的矩形一定有一条边与凸包某条边重合。

因此先求出凸包,然后旋转卡壳求出当前最小矩形面积更新答案。

代码:

#include<bits/stdc++.h>
#define N 50005
#define eps 1e-9
using namespace std;
struct pot{
	long double x,y;
	inline pot operator+(const pot&a){return (pot){x+a.x,y+a.y};}
	inline pot operator-(const pot&a){return (pot){x-a.x,y-a.y};}
	inline long double operator^(const pot&a){return x*a.y-y*a.x;}
	inline long double operator*(const pot&a){return x*a.x+y*a.y;}
	inline pot operator*(const long double&a){return (pot){x*a,y*a};}
	inline long double dist(){return sqrt(x*x+y*y);}
	friend inline bool operator<(pot a,pot b){return fabs(a.y-b.y)<eps?a.x<b.x:a.y<b.y;}
	inline pot rev(){return (pot){-y,x};}
}p[N],ans[5],now[5];
int n,q[N],top=0;
long double sum=1e18;
inline bool cmp(pot x,pot y){
	long double tmp=(x-p[1])^(y-p[1]);
	if(fabs(tmp)>eps)return tmp>0;
	return (x-p[1]).dist()<(y-p[1]).dist();
}
inline void graham(){
	int tmp=1;
	for(int i=2;i<=n;++i)if(p[i]<p[tmp])tmp=i;
	if(tmp^1)swap(p[tmp],p[1]);
	sort(p+2,p+n+1,cmp),q[++top]=1;
	for(int i=2;i<=n;++i){
		while(top>=2&&((p[q[top]]-p[q[top-1]])^(p[i]-p[q[top-1]]))<eps)--top;
		q[++top]=i;
	}
	q[0]=q[top];
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%Lf%Lf",&p[i].x,&p[i].y);
	graham();
	for(int i=0,l=1,r=1,h=1;i<top;++i){
		long double Dis=(p[q[i+1]]-p[q[i]]).dist();
		while(((p[q[i+1]]-p[q[i]])^(p[q[h+1]]-p[q[i]]))-((p[q[i+1]]-p[q[i]])^(p[q[h]]-p[q[i]]))>-eps)h=(h+1)%top;
		while((p[q[i+1]]-p[q[i]])*(p[q[r+1]]-p[q[i]])-(p[q[i+1]]-p[q[i]])*(p[q[r]]-p[q[i]])>-eps)r=(r+1)%top;
		if(!i)l=r;
		while((p[q[i+1]]-p[q[i]])*(p[q[l+1]]-p[q[i]])-(p[q[i+1]]-p[q[i]])*(p[q[l]]-p[q[i]])<eps)l=(l+1)%top;
		long double L=(p[q[i+1]]-p[q[i]])*(p[q[l]]-p[q[i]])/Dis,R=(p[q[i+1]]-p[q[i]])*(p[q[r]]-p[q[i]])/Dis;
		long double H=fabs(((p[q[i+1]]-p[q[i]])^(p[q[h]]-p[q[i]]))/Dis),tmp=(R-L)*H;
		if(tmp<sum){
			sum=tmp;
			ans[1]=p[q[i]]+(p[q[i+1]]-p[q[i]])*(R/Dis);
			ans[2]=ans[1]+(p[q[r]]-ans[1])*(H/(ans[1]-p[q[r]]).dist());
			ans[3]=ans[2]-(ans[1]-p[q[i]])*((R-L)/(p[q[i]]-ans[1]).dist());
			ans[4]=ans[3]+ans[1]-ans[2];
		}
	}
	printf("%.5Lf\n",sum);
	int pos=1;
	for(int i=1;i<=4;++i){
		if(fabs(ans[i].x)<eps)ans[i].x=0;
		if(fabs(ans[i].y)<eps)ans[i].y=0;
	}
	for(int i=2;i<=4;++i)if(ans[i]<ans[pos])pos=i;
	for(int i=1;i<=4;++i){
		printf("%.5Lf %.5Lf\n",ans[pos].x,ans[pos].y);
		++pos;
		if(pos==5)pos=1;
	}
	for(int i=1;i<=10;++i)puts("");
	return 0;
}

2018.10.18 bzoj1185: [HNOI2007]最小矩形覆盖(旋转卡壳)的更多相关文章

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

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

  2. 洛谷 P3187 BZOJ 1185 [HNOI2007]最小矩形覆盖 (旋转卡壳)

    题目链接: 洛谷 P3187 [HNOI2007]最小矩形覆盖 BZOJ 1185: [HNOI2007]最小矩形覆盖 Description 给定一些点的坐标,要求求能够覆盖所有点的最小面积的矩形, ...

  3. BZOJ 1185: [HNOI2007]最小矩形覆盖 [旋转卡壳]

    1185: [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1435  Solve ...

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

    给你一些点,让你用最小的矩形覆盖这些点 首先有一个结论,矩形的一条边一定在凸包上!!! 枚举凸包上的边 用旋转卡壳在凸包上找矩形另外三点... 注意精度问题 #include<cstdio> ...

  5. bzoj 1185 [HNOI2007]最小矩形覆盖——旋转卡壳

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 矩形一定贴着凸包的一条边.不过只是感觉这样. 枚举一条边,对面的点就是正常的旋转卡壳. ...

  6. BZOJ 1185: [HNOI2007]最小矩形覆盖-旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标-备忘板子

    来源:旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标 BZOJ又崩了,直接贴一下人家的代码. 代码: #include"stdio.h" #include"str ...

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

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

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

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

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

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

随机推荐

  1. DSHTTPService

    DSHTTPService Filters 压缩过滤器的使用 The Filters property specifies the DataSnap communication filters for ...

  2. 用FireDAC获取 SQL SERVER错误文本信息

    SQL SERVER获取错误文本信息,BDE.adoquery一直取不到,FDQuery可以了 Some DBMS, like SQL Server, return messages as an ad ...

  3. VBA 编写类

    一.初识类 现在,请打开你的VBE,主菜单-插入-类模块. 插入了一个类模块,也就建立了一个类.类模块的名字就是类的名字.你现在看到的,她的名字叫“类1”,这是VBA按她姐妹排行给她取的的,是的,VB ...

  4. 队列queue实例(生产者和消费者模型)

    import queue, threading, time q = queue.Queue(maxsize=10)def producter(n): count = 1 while True: q.p ...

  5. Spring mvc 返回json包含双引号问题 解决

    解决方式1: @RequestMapping(value="/shopsList.json", produces = "text/html;charset=UTF-8&q ...

  6. python限制函数执行时间

    from:https://stackoverflow.com/questions/366682/how-to-limit-execution-time-of-a-function-call-in-py ...

  7. Spinnaker 介绍

    功能: 无论目标环境如何,Spinnaker 部署优势始终如一,它的功能如下: 通过灵活和可配置 Pipelines,实现可重复的自动化部署: 提供所有环境的全局视图,可随时查看应用程序在其部署 Pi ...

  8. invalid self-signed ssl certificate

    down voteaccepted Cheap and insecure answer: Add process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0& ...

  9. java script 模拟鼠标事件

    try { var selector1 = "._3-8y:first-child"; var evt = document.createEvent("MouseEven ...

  10. Retrofit2+Rxjava2 okhttp RxBus 使用记录

    学习 博客 http://blog.csdn.net/r17171709/article/details/51149350 @Query 后面跟要添加的字段 @Path 连接url里面{userId} ...