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 ...
随机推荐
- Android线程池(转)
.前言 转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52415337 使用线程池可以给我们带来很多好处,首先通过线程池中线程的重用, ...
- setuid
-r-s--x--x #s就是setuid,仅可用在二进制文件,对目录设置无效
- MySQL主服务配置文件
[mysql]port=3306socket=/var/lib/mysql/mysql.sockdefault-character-set = utf8mb4 [mysqld]server-id = ...
- DataModel doesn't have preference values
mahout和hadoop实现简单的智能推荐系统的时候,出现了一下几个方面的错误 DataModel doesn't have preference values 意思是DataModel中没有找到初 ...
- 关于bootstrap栅格系统的五等分以及八等分代码
众所周知,bootstrap的栅格系统是基于十二等分的,今天拿到设计的设计稿一看,发现一个图片list上只有8张图片,然后上网查资料,发现只能自己写css代码实现,故写博客记录代码. 以下是八等分的代 ...
- websphere7.0异常:SRVE0255E: 尚未定义要处理 /wcm 的 Web 组/虚拟主机
websphere7.0错误:SRVE0255E: 尚未定义要处理 /wcm 的 Web 组/虚拟主机. SRVE0255E: 尚未定义要处理 /wcm 的 Web 组/虚拟主机.SRVE0255E: ...
- Codeforces Round #273 (Div. 2)-B. Random Teams
http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...
- Django-C001-快速入门
此文章完成度[100%]留着以后忘记的回顾.多写多练多思考,我会努力写出有意思的demo,如果知识点有错误.误导,欢迎大家在评论处写下你的感想或者纠错. Django Django是一个开放源码的We ...
- javase(7)_Objcet类
一.Object源代码 class Object { private static native void registerNatives(); static {registerNatives();} ...
- js-DOM-css的className相关
1.在非标准的浏览器,IE8及以下的浏览器不支持className的操作,包括getElementByClassName,addClassName,removeClassName; 2.getEle ...