BZOJ 1185 [HNOI2007]最小矩形覆盖 ——计算几何
程序写的太垃圾,卡不过去。
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]最小矩形覆盖 ——计算几何的更多相关文章
- 洛谷 P3187 BZOJ 1185 [HNOI2007]最小矩形覆盖 (旋转卡壳)
题目链接: 洛谷 P3187 [HNOI2007]最小矩形覆盖 BZOJ 1185: [HNOI2007]最小矩形覆盖 Description 给定一些点的坐标,要求求能够覆盖所有点的最小面积的矩形, ...
- BZOJ:1185: [HNOI2007]最小矩形覆盖
1185: [HNOI2007]最小矩形覆盖 这计算几何……果然很烦…… 发现自己不会旋转卡壳,补了下,然后发现求凸包也不会…… 凸包:找一个最左下的点,其他点按照与它连边的夹角排序,然后维护一个栈用 ...
- BZOJ 1185: [HNOI2007]最小矩形覆盖 [旋转卡壳]
1185: [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1435 Solve ...
- bzoj 1185 [HNOI2007]最小矩形覆盖 凸包+旋转卡壳
题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...
- ●BZOJ 1185 [HNOI2007]最小矩形覆盖
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解: 计算几何,凸包,旋转卡壳 结论:矩形的某一条边在凸包的一条边所在的直线上. ( ...
- BZOJ 1185 [HNOI2007]最小矩形覆盖:凸包 + 旋转卡壳
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 题意: 给出二维平面上的n个点,问你将所有点覆盖的最小矩形面积. 题解: 先找出凸 ...
- bzoj 1185 [HNOI2007]最小矩形覆盖——旋转卡壳
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 矩形一定贴着凸包的一条边.不过只是感觉这样. 枚举一条边,对面的点就是正常的旋转卡壳. ...
- BZOJ 1185: [HNOI2007]最小矩形覆盖-旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标-备忘板子
来源:旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标 BZOJ又崩了,直接贴一下人家的代码. 代码: #include"stdio.h" #include"str ...
- 1185: [HNOI2007]最小矩形覆盖
1185: [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1426 Solve ...
随机推荐
- windows命令行快速启动软件
windows桌面上太多的应用程序快捷方式很影响美观,于是寻思使用类似Linux系统中命令行的方式来启动软件. 只需要3步: 1.建立一个目录A,用来存放快捷方式.比如,建立D:\path.并复制快捷 ...
- SVN几个重要的问题
本文不是系统地讲解SVN,只是对SVN中一些重要的或者笔者一直混淆的问题做简要归纳. SVN的安装可以参考笔者的另一篇技术随笔<SVN安装使用小结>. 1.既然能够通过SVN得到“每一个版 ...
- 洛谷 P1363 幻想迷宫
题目描述 背景 Background (喵星人LHX和WD同心协力击退了汪星人的入侵,不幸的是,汪星人撤退之前给它们制造了一片幻象迷宫.) WD:呜呜,肿么办啊…… LHX:momo...我们一定能走 ...
- COGS 133. [USACO Mar08] 牛跑步
★★★ 输入文件:cowjog.in 输出文件:cowjog.out 简单对比时间限制:1 s 内存限制:128 MB Bessie准备用从牛棚跑到池塘的方法来锻炼. 但是因为她懒,她 ...
- 120. Triangle 以及一个多维vector如何初始化
1.刚开始result的初始化写的是vector<vector<int>> result,然后再去对result[0][0] = triangle[0][0]赋值,一直报错.老 ...
- javascript中typeof、undefined 和 null
typeof 是运算符,注意不是函数,是运算符,其作用,是考察变量究竟是什么类型.或曰,是变量是否定义或是否初始化的照妖镜.返回值是字符串. undefined 表示一个对象没有被定义或者没有被初始化 ...
- 实体类和JSON对象之间相互转化
. [代码]工具类 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3 ...
- Spring框架中的aop操作之二 通过配置文件实现增强
aop表达式写法 配置文件代码: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&q ...
- ios之UIPopoverController
UIPopoverController是iPad上的iOS开发会常用到的一个组件(在iPhone设备上不允许使用),这个组件上手很简单,因为他的显示方法很少,而且参数简单,但我在使用过程中还常碰到各种 ...
- perl学习之内置变量
Perl内置特殊变量 一.正则表达式特殊变量:1.$n :包含上次模式匹配的第n个子串2.$& :前一次成功模式匹配的字符串3.$` :前次匹配成功的子串之前的内容4.$’ :前次匹配 ...