1185: [HNOI2007]最小矩形覆盖

Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special Judge
Submit: 1426  Solved: 648
[Submit][Status][Discuss]

Description

Input

 

Output

 

Sample Input

 

Sample Output

 

HINT

 

Source

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=1e5+;
const double eps=1e-;
double ans=1e60;
struct Vector{
double x,y;
Vector(double x=,double y=):x(x),y(y){}
}p[N],q[N],t[];int n,top;
Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);}
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;;}
bool operator<(Vector a,Vector b){
return fabs(a.y-b.y)<eps?a.x<b.x:a.y<b.y;
}
bool operator==(Vector a,Vector b){
return fabs(a.x-b.x)<eps&&fabs(a.y-b.y)<eps;
}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}
double Length(Vector A){return sqrt(Dot(A,A));}
double Angle(Vector A,Vector B){return acos(Dot(A,B)/(Length(A)*Length(B)));}
double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double Area2(Vector A,Vector B,Vector C){return Cross(B-A,C-A);}
bool cmp(Vector a,Vector b){
double t=(a-p[])*(b-p[]);
if(fabs(t)<eps) return Length(p[]-a)-Length(p[]-b)<;
else return t>;
}
void graham(){//凸包
for(int i=;i<=n;i++) if(p[i]<p[]) swap(p[i],p[]);
sort(p+,p+n+,cmp);
q[++top]=p[];
for(int i=;i<=n;i++){
while(top>&&(q[top]-q[top-])*(p[i]-q[top])<eps) top--;
q[++top]=p[i];
}
q[]=q[top];
}
void RC(){//旋转卡壳
int l=,r=,p=;
double L,R,D,H;
for(int i=;i<top;i++){
D=Length(q[i]-q[i+]);
while((q[i+]-q[i])*(q[p+]-q[i])-(q[i+]-q[i])*(q[p]-q[i])>-eps) p=(p+)%top;
while((q[i+]-q[i])/(q[r+]-q[i])-(q[i+]-q[i])/(q[r]-q[i])>-eps) r=(r+)%top;
if(i==) l=r;
while((q[i+]-q[i])/(q[l+]-q[i])-(q[i+]-q[i])/(q[l]-q[i])<eps) l=(l+)%top;
L=(q[i+]-q[i])/(q[l]-q[i])/D,R=(q[i+]-q[i])/(q[r]-q[i])/D;
H=(q[i+]-q[i])*(q[p]-q[i])/D;
if(H<) H=-H;
double tmp=(R-L)*H;
if(tmp<ans){
ans=tmp;
t[]=q[i]+(q[i+]-q[i])*(R/D);
t[]=t[]+(q[r]-t[])*(H/Length(t[]-q[r]));
t[]=t[]-(t[]-q[i])*((R-L)/Length(q[i]-t[]));
t[]=t[]-(t[]-t[]);
}
}
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
graham();
RC();
printf("%.5lf\n",ans);
int fir=;
for(int i=;i<;i++) if(t[i]<t[fir]) fir=i;
for(int i=;i<;i++){//某些OJ评测卡精度.. 比如,洛谷
if(fabs(t[(i+fir)%].x)<1e-) printf("0.00000 ");else printf("%.5lf ",t[(i+fir)%].x);
if(fabs(t[(i+fir)%].y)<1e-) printf("0.00000\n");else printf("%.5lf\n",t[(i+fir)%].y);
}
return ;
}
/*
Sample Input
6
1.0 3.00000
1 4.00000
2.00000 1
3 0.00000
3.00000 6
6.0 3.0 Sample Output
18.00000
3.00000 0.00000
6.00000 3.00000
3.00000 6.00000
0.00000 3.00000
*/

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

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

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

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

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

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

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

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

      就是一道凸包(枚举凸包的边作为矩形的一条边)的裸题,只是不太好打,所以犹豫到今天才打 不说了,说起AC都是泪啊,因为没有精度判断,没有判重(算距离时除0了)错了好久 拍了好久都和标称是一样的,因为 ...

随机推荐

  1. http client transfer

    背景 在平时工作中我偶尔会写一些脚本监控HTTP接口的健康状况,基本上都是发送HTTP GET或HTTP POST请求,然后检测响应内容.但一直用的是WebClient和HttpWebRequest, ...

  2. WebRTC 介绍 (转)

    google开源了WebRTC项目,网址是:http://code.google.com/p/webrtc/. WebRTC实现了基于网页的视频会议,标准是WHATWG 协议,目的是通过浏览器提供简单 ...

  3. How to debug Android Native Application with eclipse

    This blog is inspired by this tutorial http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-a ...

  4. Spring Tool Suite(STS)安装

    Spring Tool Suite是一个基于Eclipse的开发环境,可以自定义用于开发Spring应用程序.它提供了一个随时可用的环境来实现,调试,运行和部署Spring应用程序,包括Pivotal ...

  5. HDU 4587 TWO NODES 枚举+割点

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 TWO NODES Time Limit: 24000/12000 MS (Java/Other ...

  6. Springboot的Bean的Scope

    这周在项目中遇到这样一个Bug,代码大致是这样的,有一个LogEntity日志类,里面有一个InnerLog负责存储每次请求的RPCInfo相关信息, 每次请求的时候会把RPC相关信息加入到Inner ...

  7. Maven设置代理

    很多时候电信的网络对于出国不太稳定,针对一些库下载速度比较慢,所以在使用SSR出国时配置maven使用是一种不错的选择.当然,还有另一种选择,就是使用国内的镜像库. 操作步骤: 1.打开{M2_HOM ...

  8. Android入门:MVC模式(中)

    MVC 模式的最基本概念是分层设计,把我们的代码基于 View(视图).Model(模型).Controller(控制器)进行分类封装,这样做的目的是为了清晰结构,使代码更易维护和扩展. 在上一篇文章 ...

  9. 开始我的GL离屏渲染绑定[转]

    地址: http://wiki.woodpecker.org.cn/moin/lilin/swig-glBmpContext 呵呵,有了第一次的经验,我们就要开始我们的GL离屏渲染的绑定了. 关 于O ...

  10. 【IE】IE对line-height 失效的的解决方案

    微软的IE9 + Extjs3.1 确实头疼.在使用了line-height:20px 的Tree的样式,可是一直没有生效, 以下给出3中解决方式: 方案1.加padding-top: <div ...