题链:

http://www.lydsy.com/JudgeOnline/problem.php?id=1185

题解:

计算几何,凸包,旋转卡壳

结论:矩形的某一条边在凸包的一条边所在的直线上。

(证不来,网上好像也没看到证明。。。诶。。。)

通过结论,问题转化为枚举凸包每条边,然后求出当矩形的一条边在该边所在的直线上时的最小矩形

即我们需要求出在凸包上,相对与这条边的最右边,最上面和最左边的点,

而最上面的点可以通过叉积得到最优位置,

最左和最右就可以通过点积的到最优位置,(一个点积最大,一个点积最小)。

同时由于随着边的顺时针枚举,这三个东西都具有单调性,所以用旋转卡壳。

代码:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 50050
using namespace std;
const double eps=1e-10;
int sign(double x){
if(fabs(x)<=eps) return 0;
return x<0?-1:1;
}
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
void Read(){scanf("%lf%lf",&x,&y);}
};
typedef Point Vector;
bool operator < (Point A,Point B){return sign(A.x-B.x)<0||(sign(A.x-B.x)==0&&sign(A.y-B.y)<0);}
Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Point A,Point B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A,double k){return Vector(A.x*k,A.y*k);}
double operator ^ (Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double operator * (Vector A,Vector B){return A.x*B.x+A.y*B.y;}
Point D[MAXN],C[MAXN],ANS[6],tmp[6];
int Andrew(int dnt){
int cnt=0,k;
sort(D+1,D+dnt+1);
for(int i=1;i<=dnt;i++){
while(cnt>1&&sign((C[cnt]-C[cnt-1])^(D[i]-C[cnt-1]))<=0) cnt--;
C[++cnt]=D[i];
} k=cnt;
for(int i=dnt-1;i>=1;i--){
while(cnt>k&&sign((C[cnt]-C[cnt-1])^(D[i]-C[cnt-1]))<=0) cnt--;
C[++cnt]=D[i];
}
return cnt-(dnt>1);
}
double TA(Point P1,Point P2,Point P){//Triangle_Area
return fabs((P-P1)^(P-P2))/2;
}
double PP(Point P1,Point P2,Point P){//Projection_Product
return (P-P1)*(P2-P1);
}
double GL(Vector A){//Get_Length
return sqrt(A*A);
}
Vector UV(Vector A){//Unit_Vector
double len=GL(A);
return Vector(A.x*(1/len),A.y*(1/len));
}
double DTL(Point P,Point P1,Point P2){//Distant_to_Line
return fabs(((P-P1)^(P-P2))/GL(P2-P1));
}
double rectangle(Vector v,Point d,Point r,Point u,Point l){
static Vector _v,w; static double t,h;
_v=Vector(-v.y,v.x);
v=UV(v); _v=UV(_v); w=l-d;
t=(w^_v)/(v^_v);
tmp[1]=d+(v*t);
h=DTL(r,tmp[1],tmp[1]+_v);
tmp[2]=tmp[1]+v*h;
h=DTL(u,tmp[1],tmp[1]+v);
tmp[4]=tmp[1]+_v*h;
tmp[3]=tmp[1]+((tmp[2]-tmp[1])+(tmp[4]-tmp[1]));
return TA(tmp[1],tmp[3],tmp[4])+TA(tmp[1],tmp[3],tmp[2]);
}
double RC(int cnt){//Rotating_Calipers
double S=1e300,_S; C[cnt+1]=C[1];
int l,r=1,u=1;
for(int i=1;i<=cnt;i++){
while(sign(PP(C[i],C[i+1],C[r])-PP(C[i],C[i+1],C[r+1]))<=0) r=r%cnt+1;
while(sign(TA(C[i],C[i+1],C[u])-TA(C[i],C[i+1],C[u+1]))<=0) u=u%cnt+1;
if(i==1) l=r;
while(sign(PP(C[i],C[i+1],C[l])-PP(C[i],C[i+1],C[l+1]))>0) l=l%cnt+1;
_S=rectangle(C[i+1]-C[i],C[i],C[r],C[u],C[l]);
if(sign(S-_S)>0){
S=_S;for(int k=1;k<=4;k++) ANS[k]=tmp[k];
}
}
return S;
}
void printPoint(){
int p=1; for(int i=2;i<=4;i++)
if(sign(ANS[i].y-ANS[p].y)<0||(sign(ANS[i].y-ANS[p].y==0)&&sign(ANS[i].x-ANS[p].x)<0)) p=i;
for(int i=1;i<=4;i++,p=p%4+1) printf("%lf %lf\n",ANS[p].x,ANS[p].y);
}
int main(){
int n; scanf("%d",&n);
for(int i=1;i<=n;i++) D[i].Read();
printf("%.5lf\n",RC(Andrew(n)));
printPoint();
return 0;
}

  

●BZOJ 1185 [HNOI2007]最小矩形覆盖的更多相关文章

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

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

  2. BZOJ:1185: [HNOI2007]最小矩形覆盖

    1185: [HNOI2007]最小矩形覆盖 这计算几何……果然很烦…… 发现自己不会旋转卡壳,补了下,然后发现求凸包也不会…… 凸包:找一个最左下的点,其他点按照与它连边的夹角排序,然后维护一个栈用 ...

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

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

  4. bzoj 1185 [HNOI2007]最小矩形覆盖 凸包+旋转卡壳

    题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...

  5. BZOJ 1185 [HNOI2007]最小矩形覆盖:凸包 + 旋转卡壳

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 题意: 给出二维平面上的n个点,问你将所有点覆盖的最小矩形面积. 题解: 先找出凸 ...

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

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

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

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

  8. BZOJ 1185 [HNOI2007]最小矩形覆盖 ——计算几何

    程序写的太垃圾,卡不过去. GG,甘拜下风. #include <map> #include <cmath> #include <queue> #include & ...

  9. 1185: [HNOI2007]最小矩形覆盖

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

随机推荐

  1. Beta冲刺NO.1

    Beta冲刺 第一天 1. 昨天的困难 由于今天还是第一天,所以暂时没有昨天的困难. 2. 今天解决的进度 潘伟靖: 对代码进行了review 1.将某些硬编码改为软编码 2.合并了一些方法,简化代码 ...

  2. django搭建web (二) urls.py

    URL模式: 在app下的urls.py中 urlpatterns=[ url(正则表达式,view函数,参数,别名,前缀)] urlpatterns=[ url(r'^hello/$',hello. ...

  3. verilog学习笔记(1)_两个小module

    第一个小module-ex_module module ex_module( input wire sclk,//声明模块的时候input变量一定是wire变量 input wire rst_n,// ...

  4. LeetCode & 118-Pascal's Triangle-Easy

    Array Description: Given numRows, generate the first numRows of Pascal's triangle. For example, give ...

  5. centos7 安装docker

    1.首先cent7 基本是在vm上完全安装'. 2.参考官方网站安装 1.https://wiki.centos.org/AdditionalResources/Repositories OS req ...

  6. istio入门(01)istio是什么?

  7. 新概念英语(1-109)A Good Idea

    Lesson 109 A good idea 好主意 Listen to the tape then answer this question. What does Jane have with he ...

  8. angular2 学习笔记 ( 状态管理 state management )

    更新 : 2017-12-29  ng5 移除 zone.js https://zhuanlan.zhihu.com/p/29577461 zone 的用途就是拦截游览器事件, 比如 click, a ...

  9. Python之递归函数

    递归函数 初识递归函数 递归函数的定义:在一个函数里再调用这个函数本身 Python为了考虑保护内存占用情况,有一个递归深度的限制. 探究递归的默认最大深度: def foo(n): print(n) ...

  10. Lintcode373 Partition Array by Odd and Even solution 题解

    [题目描述] Partition an integers array into odd number first and even number second. 分割一个整数数组,使得奇数在前偶数在后 ...