1038: [ZJOI2008]瞭望塔
半平面交。
半平面指的就是一条直线的左面(也不知道对不对)
半平面交就是指很多半平面的公共部分。
这道题的解一定在各条直线的半平面交中。
而且瞭望塔只可能在各个点或者半平面交折线的拐点处。
求出半平面交,枚举即可。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define eps 1e-7
using namespace std;
const int maxn = 300 + 10; struct Point {
double x,y;
}p[maxn],t; struct Line {
double k,b; void init(Point p1,Point p2) {
k=(p1.y-p2.y)/(p1.x-p2.x);
b=p2.y-k*p2.x;
}
}l[maxn],s[maxn]; int n,sp;
double res=1e11; bool cmp(Line x,Line y) {
if(abs(x.k-y.k)<eps) return x.b<y.b;
return x.k<y.k;
} Point inter(Line l1,Line l2) {
Point res;
res.x=(l2.b-l1.b)/(l1.k-l2.k);
res.y=l1.k*res.x+l1.b;
return res;
} void push(Line l) {
while(sp>=2 && inter(s[sp],l).x < inter(s[sp-1],s[sp]).x) sp--;
s[++sp]=l;
} double f(double x) {
double res=0;
for(int i=1;i<=sp;i++) res=max(res,s[i].k*x+s[i].b);
return res;
} double g(double x) {
int i;
for(i=n;i&&x<p[i].x;i--);
return p[i].y+(x-p[i].x)/(p[i+1].x-p[i].x)*(p[i+1].y-p[i].y);
} int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%lf",&p[i].x);
for(int i=1;i<=n;i++) scanf("%lf",&p[i].y);
for(int i=1;i<n;i++) l[i].init(p[i],p[i+1]);
sort(l+1,l+n,cmp);
for(int i=1;i<n;i++) if(i==n-1 || abs(l[i].k-l[i+1].k)>eps) push(l[i]); for(int i=1;i<=n;i++) res=min(res,f(p[i].x)-p[i].y);
for(int i=1;i<sp;i++) {
t=inter(s[i],s[i+1]);
res=min(res,t.y-g(t.x));
}
printf("%.3lf\n",res);
return 0;
}
1038: [ZJOI2008]瞭望塔的更多相关文章
- 【BZOJ 1038】 1038: [ZJOI2008]瞭望塔
1038: [ZJOI2008]瞭望塔 Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 ...
- 1038: [ZJOI2008]瞭望塔 - BZOJ
Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折线(x1, ...
- 【BZOJ】1038: [ZJOI2008]瞭望塔
http://www.lydsy.com/JudgeOnline/problem.php?id=1038 题意:给出n个x轴各不相同的二维整点,且升序,n<=300,坐标绝对值<=10^6 ...
- bzoj 1038 [ZJOI2008]瞭望塔(半平面交)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1038 [题意] 找一个最低塔高使可以看到村庄的每一个角落. [思路] 半平面交 能够看 ...
- BZOJ 1038 ZJOI2008 瞭望塔 半平面交
题目大意及模拟退火题解:见 http://blog.csdn.net/popoqqq/article/details/39340759 这次用半平面交写了一遍--求出半平面交之后.枚举原图和半平面交的 ...
- bzoj千题计划126:bzoj1038: [ZJOI2008]瞭望塔
http://www.lydsy.com/JudgeOnline/problem.php?id=1038 本题可以使用三分法 将点按横坐标排好序后 对于任意相邻两个点连成的线段,瞭望塔的高度 是单峰函 ...
- [BZOJ1038][ZJOI2008]瞭望塔(半平面交)
1038: [ZJOI2008]瞭望塔 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2999 Solved: 1227[Submit][Statu ...
- 【BZOJ1038】[ZJOI2008]瞭望塔 半平面交
[BZOJ1038][ZJOI2008]瞭望塔 Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如 ...
- 【BZOJ 1038】[ZJOI2008]瞭望塔
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1038 [题意] [题解] 可以看到所有村子的瞭望塔所在的位置只会是在相邻两个村子所代表 ...
随机推荐
- Gitlab仓库规范实践建议
记录一下Gitlab仓库实践信息: 仓库是指一个可以git clone的地址,用于存储某个服务,模块,子系统或某类辅助代码的地方 仓库的visibility level一般设置为Private(访问需 ...
- 网格导入设置 Import settings for Meshes
原地址:http://game.ceeger.com/Components/FBXImporter-Model.html The Import Settings for a model file wi ...
- Sqli-labs less 65
Less-65 $id = '"'.$id.'"'; // Querry DB to get the correct output $sql="SELECT * FROM ...
- MySQL 操作表命令
新建表: create table Itemcats (id int(11) not null auto_increment, primary key (id)) engine=MyISAM auto ...
- PHP7安装笔记
PHP7安装笔记 时间 -- :: 喵了个咪 原文 http://www.hdj.me/php7-install-note 主题 PHP # 安装mcrypt yum install -y php-m ...
- 快速编写HTML,CSS代码的有力工具Emmet插件
Emmet 是一个编辑器插件,它以一种简写的语法规则可用于快速编写html或css文档内容,它支持多种编辑器. 从官网:http://emmet.io/ 可下载各个编辑器的插件.notepad++ 插 ...
- ZOJ 2971 Give Me the Number;ZOJ 2311 Inglish-Number Translator (字符处理,防空行,strstr)
ZOJ 2971 Give Me the Number 题目 ZOJ 2311 Inglish-Number Translator 题目 //两者题目差不多,细节有点点不一样,因为不是一起做的,所以处 ...
- 【bzoj2434-阿狸的打字机】AC自动机+fail树+优化
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=23083 Description 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一 ...
- Android应用的核心基础
Android4开发入门经典 之 第二部分:Android应用的核心基础 Android应用中的组件 Application Components Android应用中最主要的组件是: 1:Activ ...
- Linux命令-date
[root@localhost ~]# date 2016年 09月 07日 星期三 :: CST [root@localhost ~]# date "+%Y" [root@loc ...