传送门

题意:给出一个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. 源码:Java集合源码之:数组与链表(一)

    数组和链表是数据结构中最基本的部分. 数组 在java中,数组定义为一种基本类型,其可以通过下标获取到对应位置的数据.那么这种结构的数据,在内存中是怎么存放的呢? 数组在内存中是一段连续的存储单元,每 ...

  2. DBus send byte array over gdbus ----Send dbus data

    遇到一个问题,如何通过dbus传送uint8数组元素 有3种方法, 1.直接传 ay 2.传  a(y) 3.xml定义为 ay,但是通过annotation 强行将 guchar 转为GVarian ...

  3. DBsever工具连接mysql数据库

    当我们安装网DBeaver的时候,怎么通过这个工具来连接Mysql数据库呢 像这个地方就按平时你的数据库信息输入就可以了 接下来配置JDBC的内容 重点说一下驱动包的版本问题,因为我安装的mysql是 ...

  4. 如何使用jQuery从字符串中删除最后一个字符

    如何使用jQuery从字符串中删除最后一个字符 1.string.slice(0,-1) 2.str.substring(0,str.length-1)

  5. 论文 | YOLO(You Only Look Once)目标检测

    论文:You Only Look Once: Unified, Real-Time Object Detection 原文链接:https://arxiv.org/abs/1506.02640 背景介 ...

  6. mongo官方企业版安装及数据库授权使用

    通过安装.deb包的方式,系统是Ubuntu 16.04 1. Import the public key used by the package management system.(导入包管理系统 ...

  7. Spring的生命周期

    转:https://blog.csdn.net/liuxilil/article/details/4676088 Spring的生命周期. 容器启动,实例化所有实现了BeanFactoyPostPro ...

  8. android 开发 ScrollView 控件的一些api描述与自定义ScrollView接口回调方法

    1.正常使用ScrollView控件的一些api详解. package com.example.lenovo.mydemoapp.scrollViewDemo; import android.supp ...

  9. 【学习】DataFrame&Series类【pandas】

    参考链接:http://blog.csdn.net/yhb315279058/article/details/50226027 DataFrame类: DataFrame有四个重要的属性: index ...

  10. TCARS: Time- and Community-Aware Recommendation System(时间感知和社区感知推荐系统)

    随着用户在物品上产生了大量行为,推荐系统成为了线上系统的重要组成部分.推荐系统算法使用用户对物品的行为信息以及上下文数据为每个用户推荐一组物品.算法根据用户之间及物品之间的相似度建立.本文介绍了一个基 ...