程序写的太垃圾,卡不过去。

GG,甘拜下风。

#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)
//#define double long double
#define eps 1e-8
#define ll long long
#define mp make_pair struct Vector{
double x,y;
void print()
{
printf("Vector -> (%.3f,%.3f)\n",x,y);
}
}; struct Point{
double x,y;
void print()
{
printf("%.5f %.5f\n",x+eps,y+eps);
}
}; int n; Vector operator - (Point a,Point b)
{Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;} Point operator + (Point a,Vector b)
{Point ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;} Vector Vertical (Vector a)
{Vector ret;ret.x=-a.y;ret.y=a.x;return ret;} double operator * (Vector a,Vector b)
{return a.x*b.y-a.y*b.x;} Vector operator * (Vector a,double b)
{Vector ret;ret.x=a.x*b;ret.y=a.y*b;return ret;} Point Node (Point P1,Vector V1,Point P2,Vector V2)
{return P1+V1*((V2*(P1-P2))/(V1*V2));} Point a[50005]; void Test()
{
printf("Test : \n");
Point P1,P2;Vector V1,V2;
P1.x=0;P1.y=1;V1.x=1;V1.y=1;
P2.x=1;P2.y=0;V2.x=1;V2.y=2;
Node(P1,V1,P2,V2).print();
} bool cmp(Point a,Point b)
{return fabs(a.x-b.x)<eps?a.y<b.y:a.x<b.x;} Point sta[50005];
int top=0; void Andrew()
{
sta[++top]=a[1];
F(i,2,n)
if (fabs(a[i].x-a[i-1].x)>=eps||fabs(a[i].y-a[i-1].y)>=eps){
while (top>=2&&(sta[top]-sta[top-1])*(a[i]-sta[top])<0) top--;
sta[++top]=a[i];
}
int lower=top;
D(i,n-1,1)
if (fabs(a[i].x-a[i+1].x)>=eps||fabs(a[i].y-a[i+1].y)>=eps){
while (top-lower>=1&&(sta[top]-sta[top-1])*(a[i]-sta[top])<0) top--;
sta[++top]=a[i];
}
} double Dot(Vector a,Vector b)
{return a.x*b.x+a.y*b.y;} double Len(Vector a)
{
return Dot(a,a);
} void Finout()
{
freopen("in.txt","r",stdin);
} Point now[4],ans[4];
double tmp=1e18,nowans; void Rotating()
{
int l=top-1,r=3,p=2;
while (Dot(sta[2]-sta[1],sta[l]-sta[1])>Dot(sta[2]-sta[1],sta[l-1]-sta[1])) l--;
while (Dot(sta[2]-sta[1],sta[r]-sta[1])<Dot(sta[2]-sta[1],sta[r+1]-sta[1])) r++;
F(i,1,top-1)
{
while (Dot(sta[i+1]-sta[i],sta[l]-sta[i])>Dot(sta[i+1]-sta[i],sta[l+1]-sta[i])) l=l%top+1;
while (Dot(sta[i+1]-sta[i],sta[r]-sta[i])<Dot(sta[i+1]-sta[i],sta[r+1]-sta[i])) r=r%top+1;
while ((sta[i+1]-sta[i])*(sta[p]-sta[i])<(sta[i+1]-sta[i])*(sta[p+1]-sta[i])) p=p%top+1;
now[0]=Node(sta[i],sta[i+1]-sta[i],sta[l],Vertical(sta[i+1]-sta[i]));
now[1]=Node(sta[i],sta[i+1]-sta[i],sta[r],Vertical(sta[i+1]-sta[i]));
now[2]=Node(sta[p],sta[i+1]-sta[i],sta[r],Vertical(sta[i+1]-sta[i]));
now[3]=Node(sta[p],sta[i+1]-sta[i],sta[l],Vertical(sta[i+1]-sta[i]));
if ((nowans=sqrt(Len(now[0]-now[1])*Len(now[1]-now[2])))<tmp)
{
F(j,0,3) ans[j]=now[j];
tmp=nowans;
}
}
int st=-1;Point stp;
stp.x=1e18;stp.y=1e18;
F(i,0,3)
if (fabs(ans[i].y-stp.y)<eps?ans[i].x<stp.x:ans[i].y<stp.y)
st=i,stp=ans[i];
printf("%.5f\n",tmp+eps);
F(i,0,3) ans[(i+st)%4].print();
} int main()
{
scanf("%d",&n);
F(i,1,n) scanf("%lf%lf",&a[i].x,&a[i].y);
sort(a+1,a+n+1,cmp);
Andrew();
Rotating();
}

  

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]最小矩形覆盖

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解: 计算几何,凸包,旋转卡壳 结论:矩形的某一条边在凸包的一条边所在的直线上. ( ...

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

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

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

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

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

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

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

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

随机推荐

  1. 状态压缩---状态压缩dp第一题

    标签: ACM 题目: Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; ...

  2. Spring Boot配置文件大全

    Spring Boot配置文件大全 ############################################################# # mvc ############## ...

  3. jquery插件serializeFormToObject

    $.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() ...

  4. 1991: C语言实验——大小写转换

    1991: C语言实验——大小写转换 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 183  Solved: 109[Submit][Status][We ...

  5. rpn网络结构再分析

    这是rpn网络train阶段的网络结构图 rpn_conv1之前的网络是特征提取层,也是和fast rcnn共享的层.rpn_conv1是一层1*1的卷积,这一层是单独为rpn网络多提取一层特征,这一 ...

  6. ios之UIToolBar

    toolbar除了可以和navigationController一起用之外,也可以独立用到view里.工具栏UIToolbar – 一般显示在底部,用于提供一组选项,让用户执行一些功能,而并非用于在完 ...

  7. 文件操作-cd

    cd命令是linux实际使用当中另一个非常重要的命令,本文就为大家介绍下Linux中cd命令的用法. 转载自 https://www.cnblogs.com/waitig/p/5880719.html ...

  8. python3.x 多路IO复用补充asyncio

    asyncio模块是python之父写的模块,按说应该是靠谱的,python3.6版本定义为稳定版本. 说明书:https://docs.python.org/3/library/asyncio.ht ...

  9. linux系统产生随机数的6种方法

    linux系统产生随机数的6种方法 方法一:通过系统环境变量($RANDOM)实现: [root@test ~]# echo $RANDOM 11595 [root@test ~]# echo $RA ...

  10. 前端开发中提到的“脚手架”到底指什么,CLI?gulp 和 gulp-cli有什么区别

    一般来说,脚手架是帮你减少「为减少重复性工作而做的重复性工作」的工具. gulp和gulp-cli的区别可以看这个task - what does gulp-"cli" stand ...