学习了半平交面。

我这里写的是训练指南中的双端队列,每次判断是否删去更优然后更新。

看hzwer中有一处不太明白就是为何要将两段加入队列

后来对拍出错才知道是因为精度,当两线重合时他们叉积返回值是一个极小值

所以判断一下精度即可。

 #include<bits/stdc++.h>
using namespace std;
const int N=;
int n,m,cnt,tot;double ans=1e20,eps=1e-;
struct point{
double x,y;
}a[N],p[N];
point operator -(point a,point b){
point t;t.x=b.x-a.x;t.y=b.y-a.y;
return t;
}
double operator *(point a,point b){
return a.x*b.y-a.y*b.x;
}
struct line{
point a,b;double slop;
bool operator <(const line &B)const{
return slop==B.slop?(b-a)*(B.b-a)>:slop<B.slop;
}
}l[N],s[N];
point inter(line a,line b){
double k1,k2,t;
k1=(b.b-a.a)*(a.b-a.a);
k2=(a.b-a.a)*(b.a-a.a);
t=k1/(k1+k2);
point ans;
ans.x=b.b.x+(b.a.x-b.b.x)*t;
ans.y=b.b.y+(b.a.y-b.b.y)*t;
return ans;
}
bool jud(line a,line b,line t)
{
point pp=inter(a,b);
return (t.b-t.a)*(pp-t.a)<-eps;
}
void hpl()
{
int L=,R=;
for(int i=;i<=cnt;++i)
{
if(l[i].slop!=l[i-].slop)++tot;
l[tot]=l[i];
}
cnt=tot;tot=;
s[++R]=l[];s[++R]=l[];
for(int i=;i<=cnt;++i)
{
while(L<R&&jud(s[R-],s[R],l[i]))R--;
while(L<R&&jud(s[L+],s[L],l[i]))L++;
s[++R]=l[i];
}
while(L<R&&jud(s[R-],s[R],s[L]))R--; while(L<R&&jud(s[L+],s[L],s[R]))L++;
for(int i=L;i<R;++i)
a[++tot]=inter(s[i],s[i+]);
}
void getans()
{
for(int i=;i<=tot;++i)
{
point t;t.x=a[i].x;t.y=-;
for(int j=;j<n;++j)
if(p[j].x<=a[i].x&&p[j+].x>=a[i].x)
ans=min(ans,a[i].y-inter((line){p[j],p[j+]},(line){t,a[i]}).y);
}
for(int i=;i<=n;++i)
{
point t;t.x=p[i].x;t.y=-;
for(int j=;j<tot;++j)
if(a[j].x<=p[i].x&&a[j+].x>=p[i].x)
ans=min(ans,inter((line){a[j],a[j+]},(line){t,p[i]}).y-p[i].y);
}
}
int main()
{
// freopen("1.out","r",stdin);
// freopen("my.out","w",stdout);
scanf("%d",&n);
for(int i=;i<=n;++i)scanf("%lf",&p[i].x);
for(int i=;i<=n;++i)scanf("%lf",&p[i].y);
// p[0].x=p[1].x;p[0].y=1e9;
// p[n+1].x=p[n].x;p[n+1].y=1e9;
for(int i=;i<n;++i)l[++cnt].a=p[i],l[cnt].b=p[i+];
if(cnt<){
puts("0.000");return ;
}
for(int i=;i<=cnt;++i)
l[i].slop=atan2(l[i].b.y-l[i].a.y,l[i].b.x-l[i].a.x);
sort(l+,l++cnt);
hpl();
getans();
printf("%.3lf",ans);
return ;
}

BZOJ1038 瞭望塔的更多相关文章

  1. 【bzoj1038】瞭望塔

    [bzoj1038]瞭望塔 题意 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折 ...

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

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

  3. bzoj1038: [ZJOI2008]瞭望塔

    Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折线(x1, ...

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

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

  5. 【bzoj1038】瞭望塔 半平面交

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

  6. 【BZOJ1038】【ZJOI2008】瞭望塔 [模拟退火]

    瞭望塔 Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description 致力于建设全国示范和谐小村庄的H村村 ...

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

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

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

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

  9. 刷题总结——瞭望塔(bzoj1038)

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

随机推荐

  1. [php]http的状态码

    1.分类 100~199 表示成功接受请求,要求客户端继续提交下一次请求才能完成整个过程处理. 200~299 表示成功接收请求并已完成整个处理过程,常用200 300~399 为完成请求,客户需进一 ...

  2. 【CodeForces】908 D. New Year and Arbitrary Arrangement

    [题目]Good Bye 2017 D. New Year and Arbitrary Arrangement [题意]给定正整数k,pa,pb,初始有空字符串,每次有pa/(pa+pb)的可能在字符 ...

  3. Amcharts 柱状图和线形图

    最近需要学习 Amcharts ,他的图表功能确实很强大.但是网上搜索到的教程很少,开始学起的确有点不方便.于是我决定把我学习的觉得好的途径,放到博客上. 下面的代码可以直接复制,但是文件要从官网上下 ...

  4. three.js_camera相机

    https://blog.csdn.net/yangnianbing110/article/details/51275927 文章地址

  5. php简单文件管理器——php经典实例

    <html> <head> <title>文件管理</title> <meta charset='utf-8' /> </head&g ...

  6. 16级第二周寒假作业E题

    Home_W的位运算4 TimeLimit:2000MS  MemoryLimit:128MB 64-bit integer IO format:%I64d Problem Description 给 ...

  7. django【ORM】 通过外键字段找对应类

    两个方法其实是一种,用哪个都行,看实例:   方法一: 从list_filter中的字符串,找到model对象的字段,然后得到这个外键对应的类 循环,把list_filter中对应的类所有对象 方法二 ...

  8. sicily 1240. Faulty Odometer

    Description You are given a car odometer which displays the miles traveled as an integer. The odomet ...

  9. selenium grid应用2-多节点执行用例

    启动远程 node我们目前启动的 Hub 与 node 都是在一台主机.那么要在其它主机启动 node 必须满足以下几个要求: 1)本地 hub 主机与远程 node 主机之间可以相互 ping 通 ...

  10. oracle只要第一条数据SQL

    select * from ( select * from COMMON_BIZREL_WF where sponsor is not null order by serialid ) where r ...