半平面交后,可能成为答案的点就是凸包上的点 和 山峰(分段函数的分段点).

枚举一下就行了.

#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int MAXN = 505;
inline double sqr(double x) { return x*x; }
inline double dcmp(double x) {if(x < -eps) return -1;if(x > eps) return 1;return 0;
}
struct Point {double x, y;Point(){}Point(const double &x, const double &y):x(x), y(y){}inline Point operator +(const Point &o)const { return Point(x + o.x, y + o.y); }inline Point operator -(const Point &o)const { return Point(x - o.x, y - o.y); }inline Point operator *(const double &k)const { return Point(x * k, y * k); }inline double operator *(const Point &o)const { return x * o.y - y * o.x; }inline friend double dist(const Point &A, const Point &B) { return sqrt(sqr(A.x-B.x) + sqr(A.y-B.y)); }
}P[MAXN];
struct Line {Point p, v; double angle;Line(){}Line(const Point &p, const Point &v):p(p), v(v){angle = atan2(v.y, v.x);}inline friend bool On_Right(const Line &l, const Point &p) {return dcmp(l.v * (p - l.p)) <= 0;}inline bool operator <(const Line &o)const {if(!dcmp(angle-o.angle))return dcmp(v * (o.p - p)) < 0;return angle < o.angle;}inline friend Point Get_Intersection(const Line &l1, const Line &l2) {Point u = l1.p - l2.p;double k = (l2.v * u) / (l1.v * l2.v);return l1.p + l1.v * k;}inline double f(double x) {return p.y + (x-p.x)/v.x * v.y;}
}arr[MAXN], q[MAXN]; int top;
inline void Insert(const Line &l) {while(top > 1 && On_Right(l, Get_Intersection(q[top-1], q[top]))) --top;q[++top] = l;
}
int n, m, tot;
double x[MAXN], y[MAXN];
inline double f(double X) {double re = 0;for(int i = 1; i <= top; ++i)re = max(re, q[i].f(X));return re;
}
inline double g(double X) {int i = upper_bound(x + 1, x + n + 1, X) - x - 1;return y[i] + (X-x[i])/(x[i+1]-x[i])*(y[i+1]-y[i]);
}
int main() {scanf("%d", &n);for(int i = 1; i <= n; ++i) scanf("%lf", &x[i]);for(int i = 1; i <= n; ++i) {scanf("%lf", &y[i]);if(i > 1) arr[++tot] = Line(Point(x[i-1], y[i-1]), Point(x[i]-x[i-1], y[i]-y[i-1]));}sort(arr + 1, arr + tot + 1);q[++top] = arr[1];for(int i = 2; i <= tot; ++i)if(dcmp(arr[i].angle-arr[i-1].angle))Insert(arr[i]);double ans = 1e15;for(int i = 1; i <= n; ++i)ans = min(ans, f(x[i]) - y[i]);for(int i = 2; i <= top; ++i) {Point now = Get_Intersection(q[i], q[i-1]);ans = min(ans, now.y - g(now.x));}printf("%.3f\n", ans);
}

BZOJ 1038: [ZJOI2008]瞭望塔相关推荐

  1. bzoj 1038 [ZJOI2008]瞭望塔

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

  2. BZOJ 1038: [ZJOI2008]瞭望塔 半平面交

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

  3. HYSBZ/BZOJ 1038 [ZJOI2008] 瞭望塔 - 计算几何

    题目描述 分析: 题目中说的"可以看见"means 在折线的每段所在直线朝x轴正方向,直线的左边一片区域(其实就是折线的每段所在直线的上面) 所以我们要求的就是此题折线所在直线相交 ...

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

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

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

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

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

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

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

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

  8. luogu P2600 [ZJOI2008]瞭望塔

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

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

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1038 [题意] [题解] 可以看到所有村子的瞭望塔所在的位置只会是在相邻两个村子所代表 ...

最新文章

  1. Android的按钮单击事件及监听器的实现方式
  2. 关于错误提示:此实现不是 Windows 平台 FIPS 验证的加密算法的一部分的解决方案...
  3. chromium浏览器_微软将全面向Windows 10用户推送Chromium版Edge浏览器
  4. jquery节点查询
  5. oracle数据库连接违反,Oracle 数据库连接的一些坑
  6. python调试代码举例
  7. Concurrent and Parallel
  8. rsa加密算法_cryptography---RSA算法
  9. html 怎么设置时间函数,JavaScript日期函数 - 计时器、innerHTML
  10. Ninject学习(一) - Dependency Injection By Hand
  11. html5 加上魔法,简单易懂的React魔法(28):是时候添加一些CSS样式了
  12. 51单片机学习笔记0 -- 仿真软件安装(Protues8.0)
  13. 计算机组装有哪些,详解电脑组装配置有哪些
  14. linux点亮硬盘locat,Linux中locate whereis which find grep5种查询命令总结
  15. CS 251 Assignment 12 知识点总结与注意
  16. 松翰单片机--SN8F5702学习笔记(七)TIMER0、TIMER1
  17. 介数中心度与紧密中心度_将开发团队与技术紧密结合的6种方法
  18. matlab 三角函数 积化和差,瞬间记住三角函数和差化积积化和差公式
  19. USB xHCI控制器使用总结
  20. python实现简单舒尔方格

热门文章

  1. 2018-2020年CMEF医博会展区产品分类
  2. 【ROS Gazebo专题】四、将Fetch机器人放到Gazebo中进行玩耍
  3. springboot整合rocketMQ记录 实现发送普通消息,延时消息
  4. 字符编码--字符与数字的对应
  5. [MySQL数据库]-基础多表练习题---员工工资
  6. hp计算机控制面板,HP5000打印机控制面板菜单解释
  7. 【网安神器篇】——mimikatz系统取证工具
  8. 嵌入式系统下Microwindows的实现
  9. NeurIPS 2018 | 腾讯AI Lab参与提出基于随机路径积分的差分估计子
  10. [简单逻辑学]逻辑学的基本原理——普遍命题