传送门

题意:给出一个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. autofac中文文档

    https://autofaccn.readthedocs.io/zh/latest/index.html

  2. 将打印(printk/printf)及时写入文件的方法

    问题是这样的,在测试一个gps的app的时候,我使用脚本  “ gps_test_app  > /tmp/gps_log.txt &" 但是但是,去查看gps_log.txt的 ...

  3. pygame 简单播放音乐程序

    环境: python2.7 pygame 功能: 播放指定目录下的歌曲(暂时mp3),可以上一曲.下一曲播放. 文件目录: font  字体文件夹 image  图片文件夹 music  音乐文件夹 ...

  4. xlrd 和xlwt 对Excel的操作

    xlrd与xlwt库的异同点对比 相同点 都支持对Excel文件格式为xls的文件进行操作 不同点 xlrd只支持对Excel文件格式为xls文件的读取 xlwt只支持对Excel文件格式为xls文件 ...

  5. Dubbo源码解析之registry注册中心

    阅读须知 dubbo版本:2.6.0 spring版本:4.3.8 文章中使用/* */注释的方法会做深入分析 正文注册中心是Dubbo的重要组成部分,主要用于服务的注册与发现,我们可以选择Redis ...

  6. java——IO流01

    移动文件有一种简单方法,不需要复制文件再删除文件. package com.unir.test01; import java.io.File; import java.io.IOException; ...

  7. orcal 安装失败解决办法

    若安装失败

  8. Mybatis-spring 传统dao开发

    jdbc.properties jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mybatis?chara ...

  9. leetcode538

    /** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...

  10. 微信小程序 用户登录 服务器端(TP5.1)实现

    先来看官方提供的流程图: 客户端: 小程序客户端通过 wx.login() 获取登录code , 然后将code当做参数传递到服务器. getToken(){ var that = this; wx. ...