传送门

题意:给出一个nnn个点的轮廓,要求找一个高度最小的点使得它能够看见所有拐点。


思路:之间建半平面交然后取半平面交上的每个交点和每个轮廓更新答案即可。

代码:

#include<bits/stdc++.h>
#define ri register int
using namespace std;
typedef long long ll;
const int N=305;
struct pot{
    double x,y;
    pot(double _x=0,double _y=0):x(_x),y(_y){}
    friend inline pot operator+(const pot&a,const pot&b){return pot(a.x+b.x,a.y+b.y);}
    friend inline pot operator-(const pot&a,const pot&b){return pot(a.x-b.x,a.y-b.y);}
    friend inline double operator^(const pot&a,const pot&b){return a.x*b.y-a.y*b.x;}
    friend inline pot operator*(const double&a,const pot&b){return pot(a*b.x,a*b.y);}
}a[N];
struct L{
    pot a,b;
    double ang;
    L(pot _a=pot(0,0),pot _b=pot(0,0),double _ang=0):a(_a),b(_b),ang(_ang){}
    friend inline bool operator<(const L&a,const L&b){return a.ang==b.ang?((b.b-a.a)^(b.b-b.a))>0:a.ang<b.ang;}
}l[N];
inline pot inter(const L&a,const L&b){
    double k1=(b.b-a.b)^(b.b-a.a),k2=(b.a-a.a)^(b.a-a.b),k=k2/(k1+k2);
    return b.a+k*(b.b-b.a);
}
int n,m;
inline bool check(const L&a,const L&b,const L&c){
    pot tmp=inter(c,b);
    return ((a.b-tmp)^(a.a-tmp))>0;
}
inline void hpi(L a[]){
    static int top;
    sort(l+1,l+n);
    m=0;
    for(ri i=1;i<n;++i)if(i==1||l[i].ang!=l[i-1].ang)l[++m]=l[i];
    top=2;
    for(ri i=3;i<=m;++i){
        while(top>1&&check(l[top-1],l[top],l[i]))--top;
        l[++top]=l[i];
    }
    m=top;
}
inline int read(){
    int ans=0;
    bool f=1;
    char ch=getchar();
    while(!isdigit(ch))f^=(ch=='-'),ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return f?ans:-ans;
}
int main(){
    n=read();
    for(ri i=1;i<=n;++i)a[i].x=read();
    for(ri i=1;i<=n;++i)a[i].y=read();
    for(ri i=2;i<=n;++i)l[i-1]=L(a[i-1],a[i],atan2(a[i].y-a[i-1].y,a[i].x-a[i-1].x));
    hpi(l);
    double ans=1e18;
    for(ri i=1,j=1;i<=n;++i){
        while(j<m&&inter(l[j],l[j+1]).x<a[i].x)++j;
        pot tmp=inter(l[j],L(a[i],pot(a[i].x,-1),0.0));
        ans=min(ans,tmp.y-a[i].y);
    }
    for(ri i=1,j=1;i<m;++i){
        pot tmp=inter(l[i],l[i+1]),upd;
        if(tmp.x<a[1].x)continue;
        while(j<n&&a[j+1].x<tmp.x)++j;
        if(j==n)continue;
        upd=inter(L(a[j],a[j+1]),L(pot(tmp.x,-1),tmp));
        ans=min(ans,tmp.y-upd.y);
    }
    printf("%.3lf",ans);
    return 0;
}

2019.02.21 bzo1038: [ZJOI2008]瞭望塔(半平面交)的更多相关文章

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

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

  2. 「BZOJ1038」「洛谷P2600」「ZJOI2008」瞭望塔 半平面交+贪心

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

  3. bzoj 1038 瞭望塔 半平面交+分段函数

    题目大意 给你一座山,山的形状在二维平面上为折线 给出\((x_1,y_1),(x_2,y_2)...(x_n,y_n)\)表示山的边界点或转折点 现在要在\([x_1,x_n]\)(闭区间)中选择一 ...

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

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

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

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

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

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

  7. bzoj 1038 [ZJOI2008]瞭望塔(半平面交)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1038 [题意] 找一个最低塔高使可以看到村庄的每一个角落. [思路] 半平面交 能够看 ...

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

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

  9. 1038: [ZJOI2008]瞭望塔

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

随机推荐

  1. Struts2 xxAction-validation.xml使用

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE validators PUBLIC &quo ...

  2. CDC工具使用

    最近一直在搞CDC (clock domain crossing) 方面的事情,现在就CDC的一些知识点进行总结. 做CDC检查使用的是0in工具. 本来要 写一些关于 CDC的 知识点,临时有事,要 ...

  3. Vue 目录结构 绑定数据 绑定属性 循环渲染数据

    一.目录结构分析 node_modules 项目所需要的各种依赖 src 开发用的资源 assets 静态资源文件 App.vue 根组件 main.js 配置路由时会用 .babelrc 配置文件 ...

  4. 杂谈1.py

    Python命名规则: 1. 组成:数字/字母/下划线 只能以字母,下划线开头 不能包含空格 避免Python关键字和函数名 简短且具有描述性 描述数据形态及支持操作 Python动态类型 变量无类型 ...

  5. day40数据库之表的相关操作

    数据库之表的相关操作1.表的操作: 1.创建表的语法:        create table 表名(              id   int(10)   primary key auto_inc ...

  6. redis的缓冲击穿|缓冲雪崩|缓冲淘汰

    Redis 的缓存穿透和击穿 查询数据 缓存中有,从缓存中返回 缓存中没有,从数据库中查找,数据库中命中结果 ,将查询到的数据保存到缓存中 缓存中没有,从数据库中查找,数据库中也没有 , 不在缓存中保 ...

  7. 1732157 - Collecting diagnosis information for SAP HANA [VIDEO]

    Symptom SAP Support asked you to provide a collection of the relevant diagnosis files (also known as ...

  8. SpringBoot 之jsp

    Boot 内嵌的tomcat 是不支持jsp 的, jetty 也是. 虽然boot也是有默认配置一个InternalResourceViewResolver ,但是它并不像我们在springmvc ...

  9. android toolbar效果

    layout下的layout_main.xml: <?xml version="1.0" encoding="utf-8"?> <Relati ...

  10. Python 多线程、进程

    本节内容 操作系统发展史介绍 进程.与线程区别 python GIL全局解释器锁 线程 语法 join 线程锁之Lock\Rlock\信号量 将线程变为守护进程 Event事件 queue队列 生产者 ...