想到了BYVoid dalao出过的一道题,

这个可以看作其中的一个子问题。

先求半平面交,然后再枚举分段函数转捩点处之高度即可。

如果是浮空岛可以直接求半平面交最低点,好像容易一些。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#define double long double
using namespace std;
int n,cnt,tot;
double ans;
struct P{
double x,y;
}p[3000],a[3000];
P vec(P a,P b){
P s;
s.x=a.x-b.x;
s.y=a.y-b.y;
return s;
}
double xplus(P a,P b){
return a.x*b.y-b.x*a.y;
}
struct L{
P a,b;
double slope;
friend bool operator < (L aa,L ab){
if(aa.slope!=ab.slope) return aa.slope<ab.slope;
else return xplus(vec(aa.b,aa.a),vec(ab.b,aa.a))>0;
}
}l[3000],que[3000];
P inter(L a,L b){
double k1,k2,t;
k1=xplus(vec(b.b,a.a),vec(a.b,a.a));
k2=xplus(vec(a.b,a.a),vec(b.a,a.a));
t=k1/(k1+k2);
P ret;
ret.x=b.b.x+t*(b.a.x-b.b.x);
ret.y=b.b.y+t*(b.a.y-b.b.y);
return ret;
}
bool check(L a,L b,L t){
P s=inter(a,b);
return xplus(vec(t.b,t.a),vec(s,t.a))<0;
}
void preact(){
p[0].x=p[1].x,p[0].y=100001;
p[n+1].x=p[n].x,p[n+1].y=100001;
for(int i=1;i<=n;++i){
l[++cnt].a=p[i-1];l[cnt].b=p[i];
l[++cnt].a=p[i];l[cnt].b=p[i+1];
}
for(int i=1;i<=cnt;++i)
l[i].slope=atan2(l[i].b.y-l[i].a.y,l[i].b.x-l[i].a.x);
sort(l+1,l+cnt+1);
return ;
}
void hpi(){
int ll=1,rr=0;tot=0;
for(int i=1;i<=cnt;++i){
if(l[i].slope!=l[i-1].slope) ++tot;
l[tot]=l[i];
}
cnt=tot;tot=0;
que[++rr]=l[1],que[++rr]=l[2];
for(int i=3;i<=cnt;++i){
while(ll<rr&&check(que[rr-1],que[rr],l[i])) --rr;
while(ll<rr&&check(que[ll+1],que[ll],l[i])) ++ll;
que[++rr]=l[i];
}
while(ll<rr&&check(que[rr-1],que[rr],que[ll])) --rr;
while(ll<rr&&check(que[ll+1],que[ll],que[rr])) ++ll;
for(int i=ll;i<rr;++i)
a[++tot]=inter(que[i],que[i+1]);
return ;
}
void getans(){
for(int i=1;i<=tot;++i){
P posnow;
posnow.x=a[i].x;
posnow.y=-1;
for(int j=1;j<n;++j)
if(a[i].x>=p[j].x&&a[i].x<=p[j+1].x)
ans=min(ans,a[i].y-inter((L){p[j],p[j+1]},(L){posnow,a[i]}).y);
}
for(int i=1;i<=n;++i){
P nowpos;
nowpos.x=p[i].x;
nowpos.y=-1;
for(int j=1;j<tot;++j)
if(a[j].x<=p[i].x&&a[j+1].x>=p[i].x)
ans=min(ans,inter((L){a[j],a[j+1]},(L){nowpos,p[i]}).y-p[i].y);
}
return ;
}
inline int read(){
int i=0,f=1;
char ch;
for(ch=getchar();ch>'9'||ch<'0';ch=getchar())
if(ch=='-') f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())
i=(i<<3)+(i<<1)+(ch^48);
return i*f;
}
int main(){
n=read();
ans=1e60;
for(int i=1;i<=n;++i)
p[i].x=read();
for(int i=1;i<=n;++i)
p[i].y=read();
preact();
hpi();
getans();
printf("%.3Lf",ans);
return 0;
}

ZJOI2008 瞭望塔相关推荐

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

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

  2. bzoj1038 [ZJOI2008]瞭望塔(半平面交)

    bzoj1038 [ZJOI2008]瞭望塔 原题地址:http://www.lydsy.com/JudgeOnline/problem.php?id=1038 题意: 村中要建立一个瞭望塔,我们将H ...

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

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

  4. bzoj 1038 [ZJOI2008]瞭望塔

    1038: [ZJOI2008]瞭望塔 Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 2438  Solved: 1004 [Submit][Sta ...

  5. luogu P2600 [ZJOI2008]瞭望塔

    luogu P2600 [ZJOI2008]瞭望塔 大意 题目讲得很清楚啊 题解 可以发现,那个点一定是某两条直线的交点 然后直接枚举两条直线就好了 // luogu-judger-enable-o2 ...

  6. 【BZOJ 1038】 [ZJOI2008]瞭望塔

    1038: [ZJOI2008]瞭望塔 Time Limit: 10 Sec   Memory Limit: 162 MB Submit: 973   Solved: 428 [ Submit][ S ...

  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<=300也 ...

最新文章

  1. 神策数据算法专家:推荐系统的实践与思考(下)
  2. 统计日志中ip访问次数并排序的三种方法
  3. 企业利用Pinterest平台推广9条建议
  4. 将JSON对象带有格式的写出到文件中
  5. OSI七层与TCP/IP四层模型
  6. Batch Normailzation
  7. 分区起始位置参数溢出_Kafka分区副本分配解析
  8. Citrix StoreFront无法正常初始化
  9. 队列Q----双数组下标查找
  10. Perl脚本 — 数字IC验证
  11. Easy RM to MP3 Converter漏洞分析报告
  12. 微信公众号如何添加附件链接
  13. 考研数学第三章复习:曲率、曲率圆、曲率半径
  14. windows防火墙开启端口
  15. 谈一谈对JS闭包的理解
  16. 华为电脑怎么不上鸿蒙,我找不到不喜欢华为鸿蒙操作系统的理由
  17. 【Android】快速实现仿美团选择城市界面,微信通讯录界面
  18. mysql中db的名词解释_数据库原理名词解释
  19. 科班和非科班都适用的 Java 学习路线
  20. 关于继电器开关带来的干扰

热门文章

  1. 农村小伙艰难的复工之路
  2. whistle入门使用
  3. 两大h264视频分析工具
  4. 高跟鞋踩猫、踩狗视频下载
  5. 4~20mA电流输出芯片XTR111完整电路
  6. linux下如何清理缓存
  7. 数据流压缩原理实现(huffman编码,LZ77压缩算法)
  8. 设置echarts雷达图label标签出现的位置聚拢或发散
  9. 2018ccpc吉林 C:JUSTICE
  10. access是用来干什么的_Access是干嘛的,可以用来干什么?