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

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. 自定义可伸缩的imageView

    直接上代码 /** * 自定义可伸缩的ImageView */ public class ZoomImageView extends ImageView { /** 画笔类 **/ private P ...

  2. sysbench0.5安装和使用介绍

    sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况,sysbench支持MySQL.PostgreSQL.Oracle数据库OLTP测试.它 ...

  3. Slacklining 2017/2/7

    原文 Proline Slacklining's expansion is still in process,but it already has a professional scene.Some ...

  4. SQLite基础教程目录

    SQLite基础教程目录 SQLite主页 SQLite概述 SQLite -安装 SQLite -命令 SQLite -语法 SQLite -数据类型 SQLite -创建数据库 SQLite -附 ...

  5. Jascript原型链以及Object和Function之间的关系

    先看一个简单的function变量 function fun1(name) { this.name = name; } console.log("fun1", fun1) 从结果可 ...

  6. springboot-i18n国际化

    简介 In computing, internationalization and localization are means of adapting computer software to di ...

  7. ueditor中FileUtils.getTempDirectory()找不到

    2014-6-27 14:22:25 org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() fo ...

  8. (9)zabbix创建监控项item

    1. 创建监控项 点击配置(configuration)->主机(Hosts)->在你要配置的主机一栏上点击Items->点击create item.具体看截图,各个参数我都已经标注 ...

  9. 王小胖之 Base64编码/解码

    使用场景:编码网址作为URL参数,简单编码或加密数据,下载地址生成或解析. 实现功能:BASE64在线编码和解码. 数据实例:王小胖好啊,王小胖顶呱呱!! ~~ english 123 !@#$%^& ...

  10. (转)git clone: error: RPC failed; result=18, HTTP code = 200 解决办法

    git clone: error: RPC failed; result=18, HTTP code = 200 解决办法 分类: git2013-09-01 17:03 10753人阅读 评论(2) ...