把地面看成半平面,能看到所有位置的点所在的区域即为半平面的交

因为分段函数的极值只会在转折处或边界取到,所以对于半平面上和地面上的每一个交点都求一下距离就好了

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e3+100;
const double maxx=4e12;
struct Point{
double x,y;
Point(double xx=0,double yy=0){
x=xx,y=yy;
}
}a[maxn],p[maxn];
struct Vector{
double x,y;
Vector(double xx=0,double yy=0){
x=xx,y=yy;
}
};
struct Line{
Point p;
Vector v;
double ang;
Line(Point a=Point(),Vector b=Vector()){
p=a,v=b;
ang=atan2(v.y,v.x);
}
}q[maxn],b[maxn];
int dcmp(double x){return fabs(x)<1e-10?0:(x>0?1:-1);}
Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
Point operator + (Point a,Vector b){return Point(a.x+b.x,a.y+b.y);}
Vector operator * (double p,Vector a){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 * (Point a,Point b){return a.x*b.y-a.y*b.x;}
bool operator < (Point a,Point b){return dcmp(a.x-b.x)==0?(dcmp(a.y-b.y)<0):(a.x<b.x);}
bool operator < (Line a,Line b){return dcmp(a.ang-b.ang)==0?(dcmp(a.v*(b.p-a.p))>0):(a.ang<b.ang);}
double len(Vector a){return sqrt(a.x*a.x+a.y*a.y);}
Point glt(Line a,Line b){Vector v=a.p-b.p; return a.p+b.v*v/(a.v*b.v)*a.v;}
bool onright(Line a,Line b,Line t){Point p=glt(a,b); return dcmp(t.v*(p-t.p))<0;}
void bpm(Line *b,int &n,Point *p){
sort(b+1,b+n+1);
int l=0,r=1,tot=0;
for(int i=1;i<=n;i++){
if(b[i].ang!=b[i-1].ang) tot++;
b[tot]=b[i];
}
n=tot,q[0]=b[1],q[1]=b[2];
for(int i=3;i<=n;i++){
while(l<r&&onright(q[r],q[r-1],b[i])) r--;
while(l<r&&onright(q[l],q[l+1],b[i])) l++;
q[++r]=b[i];
}
while(l<r&&onright(q[r],q[r-1],q[l])) r--;
while(l<r&&onright(q[l],q[l+1],q[r])) l++;
n=0,q[r+1]=q[l];
for(int i=l;i<=r;i++)
b[++n]=q[i],p[n]=glt(q[i],q[i+1]);
}
int n;
void solve(Point *a,int m,Point *p,int n){
sort(p+1,p+n+1);
// for(int i=1;i<=n;i++) printf("%lf %lf\n",p[i].x,p[i].y);
int l=2;
double ans=maxx*2;
for(int i=1;i<n;i++){
while(l<m&&dcmp(p[i].x-a[l+1].x)>0) l++;
Point pz=glt(Line(a[l],a[l+1]-a[l]),Line(p[i],Vector(0,1)));
ans=min(ans,len(pz-p[i]));
}
l=1;
for(int i=2;i<m;i++){
while(l<n&&dcmp(a[i].x-p[l+1].x)>0) l++;
Point pz=glt(Line(p[l],p[l+1]-p[l]),Line(a[i],Vector(0,1)));
ans=min(ans,len(pz-a[i]));
}
printf("%.3lf\n",ans);
}
int main(){
scanf("%d",&n),n++;
for(int i=2;i<=n;i++) scanf("%lf",&a[i].x);
for(int i=2;i<=n;i++) scanf("%lf",&a[i].y);
a[1]=Point(a[2].x,maxx),a[n+1]=Point(a[n].x,maxx);
int m=n+1;
for(int i=1;i<=n;i++)
b[i]=Line(a[i],a[i+1]-a[i]);
bpm(b,n,p);
solve(a,m,p,n);
return 0;
}

Luogu-2600 [ZJOI2008]瞭望塔的更多相关文章

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

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

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

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

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

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

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

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

  5. 1038: [ZJOI2008]瞭望塔

    半平面交. 半平面指的就是一条直线的左面(也不知道对不对) 半平面交就是指很多半平面的公共部分. 这道题的解一定在各条直线的半平面交中. 而且瞭望塔只可能在各个点或者半平面交折线的拐点处. 求出半平面 ...

  6. 1038: [ZJOI2008]瞭望塔 - BZOJ

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

  7. bzoj1038: [ZJOI2008]瞭望塔

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

  8. [ZJOI2008]瞭望塔

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

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

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1038 [题意] [题解] 可以看到所有村子的瞭望塔所在的位置只会是在相邻两个村子所代表 ...

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

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

随机推荐

  1. Android开发和Android Studio使用教程

    Android studio安装和简单介绍http://www.jianshu.com/p/36cfa1614d23 是时候把Android 项目切换到Android Studio http://ww ...

  2. UML类图中的关系表示

    UML类图中的关系和表示方法 类图是用来描述程序中的类以及它们之间的关系的,使用类图可以帮助我们简化对系统的理解.在UML类图中比较常见的关系有六种,它们分别是:依赖.关联.聚合.组合.泛化.实现,这 ...

  3. HBase概念及表格设计

    HBase概念及表格设计 1. 概述(扯淡~) HBase是一帮家伙看了Google发布的一片名为“BigTable”的论文以后,犹如醍醐灌顶,进而“山寨”出来的一套系统. 由此可见: 1. 几乎所有 ...

  4. 同样的代码在java和c++中结果不同

    #include <iostream> using namespace std; /* run this program using the console pauser or add y ...

  5. xcrun: error: unable to find utility "instruments", not a developer tool or in PATH

    xcrun: error: unable to find utility "instruments", not a developer tool or in PATH   用web ...

  6. iOS流布局UICollectionView系列七——三维中的球型布局

      摘要: 类似标签云的球状布局,也类似与魔方的3D布局 iOS流布局UICollectionView系列七——三维中的球型布局 一.引言 通过6篇的博客,从平面上最简单的规则摆放的布局,到不规则的瀑 ...

  7. 像使用linux一样使用mac

    1 不能像使用windows一样使用mac 因为mac卸载不方便. 2 gcc的问题 就使用系统默认的gcc,即clang,要想使用原声的gcc是不行的,mac本身不支持.

  8. swift 一句代码补全tableView分割线

    1.swift实现分割线补全 swift一个大进步,只要设置tableView.separatorInset = UIEdgeInsets.zero即可补全分割线, 2.OC实现分割线补全 而在OC中 ...

  9. Future Promise 模式(netty源码9)

    netty源码死磕9  Future Promise 模式详解 1. Future/Promise 模式 1.1. ChannelFuture的由来 由于Netty中的Handler 处理都是异步IO ...

  10. Python菜鸟之路:Python基础-类(2)——成员、成员修饰符、异常及其他

    三大成员 在Python的面向对象中,主要包括三大成员:字段.方法.属性 字段 类成员的字段又可分为普通字段.静态字段,他们在定义和使用中有所区别,而最本质的区别是内存中保存的位置不同,代码示例如下: ...