先求半平面交,然后建塔的地方肯定是在半平面交的交点上或者是在地面线段的交点上。

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cctype>
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define maxn 1009
#define linf 1e15
using namespace std;
inline int read()
{
int x=0, f=1; char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while (isdigit(ch)) x=x*10+ch-'0', ch=getchar();
return x*f;
}
struct P{double x, y;} p[maxn], p2[maxn];
struct line{P a, b; double ang;} g[maxn], l[maxn], a[maxn], q[maxn];
P operator - (P a, P b){return (P){a.x-b.x, a.y-b.y};}
double operator * (P a, P b){return a.x*b.y-a.y*b.x;}
bool operator < (line a, line b){if (a.ang==b.ang) return (a.b-a.a)*(b.a-a.a)>0; return a.ang<b.ang;}
bool operator < (P a, P b){return a.x<b.x;}
inline P inter(line a, line b)
{
double k1=(b.b-a.a)*(a.b-a.a), k2=(a.b-a.a)*(b.a-a.a), t=k2/(k1+k2);
return (P){b.a.x+t*(b.b.x-b.a.x), b.a.y+t*(b.b.y-b.a.y)};
}
inline bool jud(line a, line b, line v){return (inter(a, b)-v.a)*(v.b-v.a)>0;} int n, m, L, R, cnt;
double ans;
int main()
{
n=read(); m=n-1;
rep(i, 1, n) p[i].x=read();
rep(i, 1, n) p[i].y=read();
rep(i, 1, m) g[i].a=p[i], g[i].b=p[i+1];
rep(i, 1, m) l[i]=g[i], l[i].ang=atan2(l[i].b.y-l[i].a.y, l[i].b.x-l[i].a.x);
sort(l+1, l+m+1);
a[++cnt]=l[1]; rep(i, 2, m) a[a[cnt].ang!=l[i].ang ? ++cnt : cnt]=l[i];
L=1, R=0, q[++R]=a[1], q[++R]=a[2];
rep(i, 3, cnt)
{
while (L<R && jud(q[R-1], q[R], a[i])) R--;
while (L<R && jud(q[L+1], q[L], a[i])) L++;
q[++R]=a[i];
}
while (L<R && jud(q[R-1], q[R], q[L])) R--;
while (L<R && jud(q[L+1], q[L], q[R])) L++;
rep(i, L, R-1)
{
p2[i]=inter(q[i], q[i+1]);
if (p2[i].x>=p[1].x && p2[i].x<=p[m+1].x) p[++n]=p2[i];
}
sort(p+1, p+1+n);
int k1=1, k2=L; ans=linf;
rep(i, 1, n)
{
double x=p[i].x;
while (k1<m && g[k1].b.x<x) k1++;
while (k2<R && p2[k2].x<x) k2++;
line v; v.a.x=v.b.x=x, v.a.y=1, v.b.y=2;
ans=min(ans, inter(v, q[k2]).y-inter(v, g[k1]).y);
}
printf("%.3lf\n", ans);
return 0;
}

BZOJ-1038 [ZJOI2008]瞭望塔的更多相关文章

  1. bzoj 1038 [ZJOI2008]瞭望塔(半平面交)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1038 [题意] 找一个最低塔高使可以看到村庄的每一个角落. [思路] 半平面交 能够看 ...

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

    题目大意及模拟退火题解:见 http://blog.csdn.net/popoqqq/article/details/39340759 这次用半平面交写了一遍--求出半平面交之后.枚举原图和半平面交的 ...

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

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

  4. 1038: [ZJOI2008]瞭望塔 - BZOJ

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

  5. 1038: [ZJOI2008]瞭望塔

    半平面交. 半平面指的就是一条直线的左面(也不知道对不对) 半平面交就是指很多半平面的公共部分. 这道题的解一定在各条直线的半平面交中. 而且瞭望塔只可能在各个点或者半平面交折线的拐点处. 求出半平面 ...

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

    http://www.lydsy.com/JudgeOnline/problem.php?id=1038 题意:给出n个x轴各不相同的二维整点,且升序,n<=300,坐标绝对值<=10^6 ...

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

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

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

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

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

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

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

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

随机推荐

  1. java中的两同两小一大原则

    子类覆盖父类要遵循“两同两小一大” “两同”即方法名相同,形参列表相同 “两小”指的是子类方法返回值类型应比父类方法返回值类型更小或相等,子类方法声明抛出的异常类应比父类方法声明抛出的异常类更小或相等 ...

  2. c#树形结构

    http://download.csdn.net/detail/rememberme001/6997235 http://bbs.csdn.net/topics/310094150 http://ww ...

  3. 用css去除chrome、safari等webikt内核浏览器对控件默认样式

    有这么一个webkit的私有属性: -webkit-appearance:none; /*去除input默认样式*/ 添加该样式,并且值为'none'时即可取消浏览器对于控件的默认样式. 另外这个属性 ...

  4. 如何在vue项目中使用md5加密

    npm安装: npm install --save js-md5 1.在需要使用的项目文件中引入: import md5 from 'js-md5'; 使用: md5('hello world') / ...

  5. Linux网络编程之"获取网络天气信息"

    需求分析: 1.需要Linux c 网络编程基础, 2.需要了解 http 协议 3.需要天气信息相关api(可以从阿里云上购买,很便宜的!) 4.需要cJSON解析库(因为获取到的天气信息一般是用c ...

  6. Mybatis 插入一条或批量插入 返回带有自增长主键记录

    首先讲一下,  插入一条记录返回主键的 Mybatis 版本要求低点,而批量插入返回带主键的 需要升级到3.3.1版本,3.3.0之前的都不行, <dependency> <grou ...

  7. Mysql操作方法类

    帮助类: using System; using System.Collections.Generic; using System.Data; using System.Linq; using Sys ...

  8. Java代码随机生成图片验证码

    package com.rchm.util.images; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2 ...

  9. python3 练习题100例 (十二)

    题目十二:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数",因为153 ...

  10. python模块之collections模块

    计数器 Counter 计数元素迭代器 elements() 计数对象拷贝 copy() 计数对象清空 clear() from collections import Counter #import ...