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

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

#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. Ubuntu安装CodeBlocks

    访问 https://launchpad.net/~damien-moore/+archive/ubuntu/codeblocks-stable,找到页面上加粗的那一段英文(以“ppa:”开头),如“ ...

  2. 盘古分词demo,盘古分词怎么用

    1.下载PanGu.dll dll地址:http://download.csdn.net/detail/dhfekl/7493687 2.将PanGu.dll和词库引入到项目 最新词库地址:http: ...

  3. applicationContext-XXX.xml和XXX-servlet.xml的区别

    1.ApplicationContext.xml  是spring 全局配置文件,用来控制spring 特性的 2.dispatcher-servlet.xml 是spring mvc里面的,控制器. ...

  4. java面试的那些事

    跳槽面临的第一个难关那就是面试吧.面试的好坏直接关乎着你年薪的多少.如何顺利完成面试的那些难题,今天我们就从java中复习一下.看看经常面试的知识点,为什么面试这些知识点, 如果你是初级的或刚毕业的j ...

  5. RHEL7安装部署ZooKeeper

    转载请注明出处:jiq•钦's technical Blog - 季义钦 文章说明: 分布式注冊中心(链接)须要安装的组件包括两个部分: 1.注冊中心服务(Zookeeper) 2.站点(Tomcat ...

  6. Linux - SVN的基本操作

    SVN的基本操作 本文地址: http://blog.csdn.net/caroline_wendy $ svn diff //显示改动 $ post-review --summary="b ...

  7. Swift开发教程--怎样设置状态栏的文字颜色

    第一步:在Info.plist中设置UIViewControllerBasedStatusBarAppearance 为NO 第二步:在viewDidLoad中加一句 UIApplication.sh ...

  8. iPhone缓存网络数据

    本文转载至 http://blog.csdn.net/wwang196988/article/details/7542918   在iPhone应用程序中,我们经常要用去网络下载一些文件,比如xml, ...

  9. poj2075

    Tangled in Cables Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6348   Accepted: 2505 ...

  10. 石子合并DP

    DP Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submit Status Pra ...