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. DATAGUARD 在线重建备库

    环境: OS: CentOS 6.5 X64 DB: oracle 10.2.0.5 故障:之前由于错误激活备库主写导致主备日志同步,重建备库 1.关闭备库,删除数据文件及控制文件,redo文件 rm ...

  2. Codeforces Round #228 (Div. 1) A

    A. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. 10. windows与linux文件共享

    1. 关闭防火墙 /etc/init.d/iptables stop 2. C:\Users\cfm>ping 192.168.232.131 正在 Ping 192.168.232.131 具 ...

  4. leetcode 141

    141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you sol ...

  5. NHibernate系列文章十九:NHibernate关系之多对多关系(附程序下载)

    摘要 NHibernate的多对多关系映射由many-to-many定义. 从这里下载本文的代码NHibernate Demo 1.修改数据库 添加Product表 添加ProductOrder表 数 ...

  6. 使用 Git 管理源代码

    在现代软件开发项目中,要成为一个有效的软件开发人员,我们必须能够与其他项目贡献者并行进行开发.源代码管理(SCM)系统不是什么新思想.为了编写一些能够更快速.简单地开发以后软件项目的软件,已经进行了很 ...

  7. JavaScript 对象 之继承对象 学习笔记

    假设,我们有个这样的需求: 两个种族,每个种族都有 名字.血量(默认200).行为(行为有 跳跃.移动速度 这些属性)等共有属性. 人族能量值比兽人多10%,兽人血量比人族多10%. 职业有战士和法师 ...

  8. Hadoop HDFS编程 API入门系列之从本地上传文件到HDFS(一)

    不多说,直接上代码. 代码 package zhouls.bigdata.myWholeHadoop.HDFS.hdfs5; import java.io.IOException; import ja ...

  9. rediscluster 集群操作(摘抄)

    一:关于redis cluster 1:redis cluster的现状 目前redis支持的cluster特性 1):节点自动发现 2):slave->master 选举,集群容错 3):Ho ...

  10. mysql 主从复制原理

    主从形式   mysql主从复制 灵活 一主一从 主主复制 一主多从---扩展系统读取的性能,因为读是在从库读取的: 多主一从---5.7开始支持 联级复制---     用途及条件   mysql主 ...