http://m.blog.csdn.net/blog/qpswwww/44105605

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define EPS 0.0000001
#define N 311
typedef double db;
const db PI=acos(-1.0);
struct Point{db x,y;};
typedef Point Vector;
Vector operator - (const Point &a,const Point &b){return (Vector){a.x-b.x,a.y-b.y};}
Vector operator * (const Vector &a,const db &k){return (Vector){a.x*k,a.y*k};}
Vector operator + (const Vector &a,const Vector &b){return (Vector){a.x+b.x,a.y+b.y};}
db Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
struct Line
{
Point p; Vector v; db ang;
Line(){}
Line(const Point &a,const Point &b)
{
v=b-a;
p=a;
ang=atan2(v.y,v.x);
if(ang<0) ang+=2.0*PI;
}
};
bool operator < (const Line &a,const Line &b){return a.ang<b.ang;}
bool OnLeft(Line l,Point a){return Cross(l.v,a-l.p)>0;}
Point GetJiaodian(Line a,Line b){return a.p+a.v*(Cross(b.v,a.p-b.p)/Cross(a.v,b.v));}
int n;
Point ps[N];
Line q[N];
int head=1,tail=1;
Line ls[N];
void BPMJ()
{
sort(ls+1,ls+n+1);
q[1]=ls[1];
for(int i=2;i<=n;++i)
{
while(head<tail&&(!OnLeft(ls[i],ps[tail-1]))) --tail;
while(head<tail&&(!OnLeft(ls[i],ps[head]))) ++head;
q[++tail]=ls[i];
if(fabs(Cross(q[tail].v,q[tail-1].v))<EPS)
{
--tail;
if(OnLeft(q[tail],ls[i].p))
q[tail]=ls[i];
}
if(head<tail)
ps[tail-1]=GetJiaodian(q[tail-1],q[tail]);
}
while(head<tail&&(!OnLeft(q[head],ps[tail-1]))) --tail;
ps[tail]=GetJiaodian(q[tail],q[head]);
}
int nn;
Point a[N];
db ans=999999999999999999.0;
#define INF 10000000000.0
int main()
{
// freopen("bzoj1038.in","r",stdin);
scanf("%d",&nn);
for(int i=1;i<=nn;++i) scanf("%lf",&a[i].x);
for(int i=1;i<=nn;++i) scanf("%lf",&a[i].y);
for(int i=1;i<nn;++i) ls[++n]=Line(a[i],a[i+1]);
ls[++n]=Line((Point){INF,INF},(Point){-INF,INF});
ls[++n]=Line((Point){-INF,INF},(Point){-INF,-INF});
ls[++n]=Line((Point){-INF,-INF},(Point){INF,-INF});
ls[++n]=Line((Point){INF,-INF},(Point){INF,INF});
BPMJ();
for(int i=head;i<=tail;++i)
for(int j=1;j<nn;++j)
if(ps[i].x>=a[j].x&&ps[i].x<=a[j+1].x)
{
db ty=a[j].y+(ps[i].x-a[j].x)/(a[j+1].x-a[j].x)*(a[j+1].y-a[j].y);
ans=min(ans,ps[i].y-ty);
break;
}
for(int i=1;i<=nn;++i)
{
for(int j=head;j<tail;++j)
if(a[i].x>=ps[j].x&&a[i].x<=ps[j+1].x)
{
db ty=ps[j].y+(a[i].x-ps[j].x)/(ps[j+1].x-ps[j].x)*(ps[j+1].y-ps[j].y);
ans=min(ans,ty-a[i].y);
}
if(a[i].x>=ps[tail].x&&a[i].x<=ps[head].x)
{
db ty=ps[tail].y+(a[i].x-ps[tail].x)/(ps[head].x-ps[tail].x)*(ps[head].y-ps[tail].y);
ans=min(ans,ty-a[i].y);
}
}
printf("%.3lf\n",ans);
return 0;
}

【半平面交】bzoj1038 [ZJOI2008]瞭望塔的更多相关文章

  1. [BZOJ1038][ZJOI2008]瞭望塔(半平面交)

    1038: [ZJOI2008]瞭望塔 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2999  Solved: 1227[Submit][Statu ...

  2. bzoj千题计划126:bzoj1038: [ZJOI2008]瞭望塔

    http://www.lydsy.com/JudgeOnline/problem.php?id=1038 本题可以使用三分法 将点按横坐标排好序后 对于任意相邻两个点连成的线段,瞭望塔的高度 是单峰函 ...

  3. [日常摸鱼]bzoj1038 [ZJOI2008]瞭望塔-模拟退火/几何

    题意:给一条平面内$n$个点的折线,要求在折线上搞一个高度$h$的瞭望塔,能够看见折线上所有的点,求$h$的最小值($n \leq 300$) updata2018.1.21 正解半平面交在另一篇里面 ...

  4. bzoj1038: [ZJOI2008]瞭望塔

    Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折线(x1, ...

  5. BZOJ-1038 [ZJOI2008]瞭望塔

    先求半平面交,然后建塔的地方肯定是在半平面交的交点上或者是在地面线段的交点上. #include <cstdlib> #include <cstdio> #include &l ...

  6. [日常摸鱼]bzoj1038[ZJOI2008]瞭望塔-半平面交

    这回好好用半平面交写一次- 看了cls当年写的代码看了好久大概看懂了-cls太强辣 #include<cstdio> #include<iostream> #include&l ...

  7. 【BZOJ1038】[ZJOI2008]瞭望塔 半平面交

    [BZOJ1038][ZJOI2008]瞭望塔 Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如 ...

  8. 【bzoj1038】瞭望塔

    [bzoj1038]瞭望塔 题意 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折 ...

  9. 【BZOJ 1038】 1038: [ZJOI2008]瞭望塔

    1038: [ZJOI2008]瞭望塔 Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 ...

随机推荐

  1. NGUI之UIPanel

    原文:http://www.tasharen.com/forum/index.php?topic=6705.0 概述 UIPanel用来收集和管理它下面所有widget的组件.通过widget的geo ...

  2. X-Cart 学习笔记(三)X-Cart框架2

    目录 X-Cart 学习笔记(一)了解和安装X-Cart X-Cart 学习笔记(二)X-Cart框架1 X-Cart 学习笔记(三)X-Cart框架2 X-Cart 学习笔记(四)常见操作 3.了解 ...

  3. 使用asmcmdcp命令把datafile从文件系统移动(move)到asm磁盘组中 针对11gR2

    使用asmcmd cp命令 把datafile从文件系统移动(move)到asm磁盘组中--针对11gR2 参考原文:How to Move a Datafile from Filesystem to ...

  4. python学习笔记(一)

    1. BeautifulSoup是一个很好用的Python写的一个HTML/XML的解析器,它可以处理不规范标记并生成剖析树(parse tree).Beautifulsoup可以对便签Object进 ...

  5. Codeforces Round #229 (Div. 2) C

    C. Inna and Candy Boxes time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. Android dispatchTouchEvent介绍

    一个最简单的屏幕触摸动作触发了一系列Touch事件:ACTION_DOWN->ACTION_MOVE->ACTION_MOVE->ACTION_MOVE...->ACTION_ ...

  7. perl脚本基础总结

    1.  单引号字符串中的\n不会被当做换行符处理. 如:'\'\\'  -->  '\  . 2.  双引号 字符串联    "Hello"."World" ...

  8. 如何将arcgis的mxd文档存储为相对路径

    在默认情况下,ArcGIS 10中地图文件mxd中添加的图层所引用的文件路径均为绝对路径.这就意味着,如果你在地图中引用了“D:\data\DEM.shp”文件,那map.mxd文件中保存的该层文件路 ...

  9. css的一种预处理器 sass

    之前觉得关于css什么的没什么,后来让别人给问住了...然后就悲催了... sass是一种css的预处理器,是一种函数式的css的编程: 主要还是看官网 http://www.w3cplus.com/ ...

  10. Visual Studio 2015完全离线安装

    虽然微软提供了Visual Studio的ISO镜像下载,但这个ISO文件并不完整,安装的过程中依然需要联网下载一些安装包,在中国特色的网络环境下导致安装过程还是非常慢的.另外,在一些网络隔离的环境中 ...