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

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

#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. Javascript属性constructor/prototype的底层原理

    在Javascript语言中,constructor属性是专门为function而设计的,它存在于每个function的prototype属性中. 这个constructor保存了指向function ...

  2. Java IO 常用类简介

    字节流 输入字节流 InputStream输入字节流的抽象类 ByteArrayInputStreambyte数组输入流 FileInputStream文件输入流 PipedInputStream管道 ...

  3. Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle

    Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...

  4. Ubuntu 16.04 关闭/打开笔记本触摸板

    由于笔记本触摸板太多灵敏,影响使用,所以禁用掉触摸板. 禁用触摸板命令: sudo rmmod psmouse 启用触摸板命令 sudo modprobe psmouse 注意:启用之后可能会有几秒钟 ...

  5. 01 linux上安装 nginx

    一:linux上安装 nginx 下载nginx:wget http://nginx.org/download/nginx-1.6.2.tar.gz 解压:tar zxvf nginx-1.6.2.t ...

  6. cocos2d-x 2.x 支持多个方向屏幕翻转

    主要改动 RootViewController.mm 的 supportedInterfaceOrientations 方法 1.四个方向 UIInterfaceOrientationMaskAll ...

  7. C# 关于类型转换 面试题

    分别分析一下两种写法是否正确.假设不对.请说明原因 写法一: short s=1; s = s + 1; 写法二: short s=1; s += 1; 解答: 写法一不对,会报出以下的错误: 无法将 ...

  8. 大华NVR设备接分别入宇视摄像机Onvif和RTSP主子码流的方案说明

    需求提要 1.各个内网现场有多种网络摄像机IPC和网络硬盘录像机NVR设备: 2.需要将这些设备统一接入到云端中心平台,进行统一的视频直播和录像回放管理: 3.由于目前IPC设备都属于高清设备,主码流 ...

  9. 算法调参 weight_ratio, weight_seqratio

    from openpyxl import Workbook import xlrd import time import Levenshtein as Le target_city_list = [' ...

  10. every row of W is a classifier for one of the classes

    every row of W is a classifier for one of the classes As we saw above, every row of W is a classifie ...