【题意分析】

  求一个下凸壳与一段折线的距离。

【解题思路】

  先把直线按斜率排序,求出下凸壳,然后枚举所有的顶点的x坐标求最短y坐标差,复杂度O(nlog2n)。

【参考代码】

 #include <algorithm>
#include <cstdio>
#define REP(i,low,high) for(register int i=(low);i<=(high);++i)
#define __function__(type) /*__attribute__((optimize("-O2"))) inline */type
#define __procedure__ /*__attribute__((optimize("-O2"))) inline */void
using namespace std; //defs {
#include <cmath>
template<typename real>
inline __function__(bool) fequals(
const real&one,const real&another,const real&eps=1e-
) {return fabs(one-another)<eps;}
template<typename real>
inline __function__(bool) funequals(
const real&one,const real&another,const real&eps=1e-
) {return fabs(one-another)>=eps;}
//} defs //geometry {
template<typename T=double> struct Point
{
T x,y; Point(const T&_x=,const T&_y=):x(_x),y(_y) {}
__function__(bool) operator==(const Point<T>&thr)const
{
return fequals(x,thr.x)&&fequals(y,thr.y);
}
__function__(bool) operator!=(const Point<T>&thr)const
{
return funequals(x,thr.x)||funequals(y,thr.y);
}
__function__(Point<T>) operator+(const Point<T>&thr)const
{
return Point<T>(x+thr.x,y+thr.y);
}
__function__(Point<T>) operator-(const Point<T>&thr)const
{
return Point<T>(x-thr.x,y-thr.y);
}
__function__(Point<T>) operator*(const T&lambda)const
{
return Point<T>(x*lambda,y*lambda);
}
__function__(Point<double>) operator/(const T&lambda)const
{
return Point<double>(double(x)/lambda,double(y)/lambda);
}
__function__(double) theta()const
{
return x>?(y<)**M_PI+atan(y/x):M_PI+atan(y/x);
}
__function__(double) theta_x()const{return x?atan(y/x):M_PI/;}
__function__(double) theta_y()const{return y?atan(x/y):M_PI/;}
};
template<typename T>
inline __function__(T) dot_product(const Point<T>&A,const Point<T>&B)
{
return A.x*B.x+A.y*B.y;
}
template<typename T>
inline __function__(T) cross_product(const Point<T>&A,const Point<T>&B)
{
return A.x*B.y-A.y*B.x;
}
template<typename T>
inline __function__(double) Euclid_distance(const Point<T>&A,const Point<T>&B)
{
return sqrt(pow(A.x-B.x,),pow(A.y-B.y,));
}
template<typename T>
inline __function__(T) Manhattan_distance(const Point<T>&A,const Point<T>&B)
{
return fabs(A.x-B.x)+fabs(A.y-B.y);
}
struct kbLine
{
//line:y=kx+b
double k,b; kbLine(const double&_k=,const double&_b=):k(_k),b(_b) {}
__function__(bool) operator==(const kbLine&thr)const
{
return fequals(k,thr.k)&&fequals(b,thr.b);
}
__function__(bool) operator!=(const kbLine&thr)const
{
return funequals(k,thr.k)||funequals(b,thr.b);
}
__function__(bool) operator<(const kbLine&thr)const{return k<thr.k;}
__function__(bool) operator>(const kbLine&thr)const{return k>thr.k;}
template<typename T>
__function__(bool) build_line(const Point<T>&A,const Point<T>&B)
{
return fequals(A.x,B.x)?:(k=double(A.y-B.y)/(A.x-B.x),b=A.y-k*A.x,);
}
__function__(double) theta_x()const{return atan(k);}
__function__(double) theta_y()const{return theta_x()-M_PI/;}
__function__(double) get(const double&x)const{return k*x+b;}
};
__function__(bool) parallel(const kbLine&A,const kbLine&B)
{
return A!=B&&(fequals(A.k,B.k)||A.k!=A.k&&B.k!=B.k);
}
__function__(Point<double>*) cross(const kbLine&A,const kbLine&B)
{
if(A==B||parallel(A,B)) return NULL; double _x=double(B.b-A.b)/(A.k-B.k);
Point<double>*ret=new Point<double>(_x,A.k*_x+A.b); return ret;
}
//} geometry static int n; double x[],y[]; int stack[]; kbLine L[]; int main()
{
scanf("%d",&n); REP(i,,n) scanf("%lf",x+i); REP(i,,n) scanf("%lf",y+i);
REP(i,,n-) L[i].build_line(Point<>(x[i],y[i]),Point<>(x[i+],y[i+]));
sort(L+,L+n); int top=stack[]=; REP(i,,n-)
{
for(;i<=n&&(L[i]==L[stack[top]]||parallel(L[i],L[stack[top]]));++i);
for(;i<=n&&top>;--top)
{
Point<>*last=cross(L[stack[top-]],L[stack[top]]),
* now=cross(L[ i ],L[stack[top]]);
if(last->x<now->x) break; delete last; delete now;
}
stack[++top]=i;
}
double ans=1e10; int j=;
REP(i,,n)
{
for(;L[stack[j]].get(x[i])>L[stack[j-]].get(x[i]);++j);
ans=min(ans,L[stack[--j]].get(x[i])-y[i]);
}
REP(i,,top)
{
Point<>*now=cross(L[stack[i-]],L[stack[i]]);
j=upper_bound(x+,x+n+,now->x)-x; kbLine tmp;
tmp.build_line(Point<>(x[j-],y[j-]),Point<>(x[j],y[j]));
ans=min(ans,now->y-tmp.get(now->x)); delete now;
}
return printf("%.3lf\n",ans),;
}

bzoj1038题解的更多相关文章

  1. 【bzoj1038】瞭望塔

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

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

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

  3. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  4. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  5. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  6. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  7. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  8. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  9. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

随机推荐

  1. Dubbox服务的提供方开发

    (1)创建Maven工程(WAR)dubboxdemo-service  ,在pom.xml中引入依赖 <project xmlns="http://maven.apache.org/ ...

  2. Unity Document

    { https://docs.unity3d.com/ScriptReference/Events.UnityEventTools.html }

  3. Delphi实现获取句柄并发送消息的方法(FindWindow、FindWindowEx、EnumChildWindows、SendMessage)

    Delphi实现获取句柄并发送消息的方法 本文以实例形式详细说明了Delphi获取句柄并发送消息的方法,具体用法说明如下: 查找另外一个窗口的句柄: handle := FindWindow(nil, ...

  4. HTML5中的Canvas和SVG

    Canvas 和 SVG 都允许我们在浏览器中创建图形,但是它们在根本上是不同的. 1 SVG SVG 是一种使用 XML 描述 2D 图形的语言. SVG 基于 XML,这意味着 SVG DOM 中 ...

  5. Angular.js分页代码

                $scope.reloadList=function(){                             $scope.findPage( $scope.pagina ...

  6. pro、pre、test、dev环境

    开发过程中四个环境分别是:pro.pre.test.dev环境,中文名字:生产环境.灰度环境.测试环境.开发环境 环境介绍: pro环境:生产环境,面向外部用户的环境,连接上互联网即可访问的正式环境. ...

  7. stl+数论——1247D

    其实也不算很难想,每个元素质因子分解后的p^c的p和c用pair的形式存在每个元素vector里 要去前面找一个数使得所有指数相加是k的倍数,那么把vector里的所有c 模 k,然后去找前面互补的数 ...

  8. Ajax请求参数为文件类型

    1.图片用get请求,回调函数中返回的数据就是流文件(至于是什么流文件还不清楚), 在回调函数中再使用post请求2.JS将文件像form表单一样提交到后台  :  https://www.cnblo ...

  9. 上传漏洞科普[1]-文件上传表单是Web安全主要威胁

    为了让最终用户将文件上传到您的网站,就像是给危及您的服务器的恶意用户打开了另一扇门.即便如此,在今天的现代互联网的Web应用程序,它是一种 常见的要求,因为它有助于提高您的业务效率.在Facebook ...

  10. shellcode加密与解密

    // Encoder.cpp : Defines the entry point for the console application.// #include "stdafx.h" ...