【BZOJ 1038】[ZJOI2008]瞭望塔
【题目链接】:http://www.lydsy.com/JudgeOnline/problem.php?id=1038
【题意】
【题解】
可以看到所有村子的瞭望塔所在的位置只会是在相邻两个村子所代表的点连成的线的半平面交内;
它求的是相对高度;
有个结论是:
最小相对高度差的点,
1.在半平面交的直线的交点处
2.在村子往上的投影处;
平面交用单调队列搞;
搞之前需要先将直线按斜率升序排;
然后就可以想象一下斜率都是0..90°的情形,然后写一些就好;
具体实现看代码;
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1000;
struct point
{
double x,y;
}points[N];
struct line
{
point a,b;
double k,c;
void get()
{
k = (a.y-b.y)/(a.x-b.x);
c = a.y-k*a.x;
}
}lines[N],sta[N];
int n,top = 0;
double ans = 1e12;
void in()
{
rei(n);
rep1(i,1,n)
ref(points[i].x);
rep1(i,1,n)
ref(points[i].y);
}
bool cmp1(line a,line b)//把线段按照斜率升序排
{
return a.k < b.k;
}
point getintersec(line a,line b)//求两条直线的交点
{
point t;
t.x = (a.c-b.c)/(b.k-a.k);
t.y = t.x*a.k+a.c;
return t;
}
void Insert(line t)//插入一条新的平面
//因为都会是往上的,所以处理起来会简单一点吧
{
while (top>=2)
{
if (getintersec(sta[top-1],sta[top]).x>getintersec(sta[top],t).x) top--;
else
break;
}
sta[++top] = t;
}
void halfpaneintersec()//搞平面交
{
rep1(i,1,n-1)
Insert(lines[i]);
}
void pre()
{
rep1(i,1,n-1)
lines[i].a = points[i],lines[i].b = points[i+1],lines[i].get();
sort(lines+1,lines+1+(n-1),cmp1);
halfpaneintersec();
}
double maxh(double x)//村子的投影往上的交点的纵坐标
{
double t = 0;
rep1(i,1,top)
{
double y = sta[i].k*x+sta[i].c;
t = max(t,y);
}
return t;
}
double jdy(double x)//平面交的直线的交点的横坐标往下的投影的交点纵坐标
{
rep1(i,2,n)
{
if (points[i].x>=x)
return points[i].y-(points[i].y-points[i-1].y)*(points[i].x-x)/(points[i].x-points[i-1].x);
}
return 0;
}
void get_ans()
{
rep1(i,1,n)
ans = min(ans,maxh(points[i].x)-points[i].y);
rep1(i,1,top-1)
{
point t = getintersec(sta[i],sta[i+1]);
ans = min(ans,t.y-jdy(t.x));
}
}
void o()
{
printf("%.3f\n",ans);
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
in();
pre();
get_ans();
o();
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【BZOJ 1038】[ZJOI2008]瞭望塔的更多相关文章
- bzoj 1038 [ZJOI2008]瞭望塔(半平面交)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1038 [题意] 找一个最低塔高使可以看到村庄的每一个角落. [思路] 半平面交 能够看 ...
- BZOJ 1038 ZJOI2008 瞭望塔 半平面交
题目大意及模拟退火题解:见 http://blog.csdn.net/popoqqq/article/details/39340759 这次用半平面交写了一遍--求出半平面交之后.枚举原图和半平面交的 ...
- 【BZOJ 1038】 1038: [ZJOI2008]瞭望塔
1038: [ZJOI2008]瞭望塔 Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 ...
- 1038: [ZJOI2008]瞭望塔 - BZOJ
Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折线(x1, ...
- 1038: [ZJOI2008]瞭望塔
半平面交. 半平面指的就是一条直线的左面(也不知道对不对) 半平面交就是指很多半平面的公共部分. 这道题的解一定在各条直线的半平面交中. 而且瞭望塔只可能在各个点或者半平面交折线的拐点处. 求出半平面 ...
- 【BZOJ】1038: [ZJOI2008]瞭望塔
http://www.lydsy.com/JudgeOnline/problem.php?id=1038 题意:给出n个x轴各不相同的二维整点,且升序,n<=300,坐标绝对值<=10^6 ...
- 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村抽象为一维的轮廓.如 ...
随机推荐
- 将exe添加到windows服务中
mongod --dbpath D:\MongoDB\data --logpath=D:\MongoDB\logs\mongodb.log --install http://www.cnblogs.c ...
- 删除dataGridview中选中的一行或多行
一.实现的功能:可以删除一行或者多行数据,并在删除前提醒是否确定进行删除! DialogResult RSS = MessageBox.Show(this,"确定要删除选中行数据码?&quo ...
- call.apply.冒充对象继承
call方法:让调用对象执行,然后第一参数是谁.调用对象的this就改变,指向谁,后边跟参数,依次对应传入 apply方法:让调用对象执行,然后第一参数是谁.调用对象的this就改变指向是谁,后边跟参 ...
- 在Java中,return null 是否安全, 为什么?
Java代码中return value 为null 是不是在任何情况下都可以,为什么不会throw NullPointerException? Java语言层面:null值自身是不会引起任何问题的.它 ...
- softmax 与 sigmoid & softmax名字的由来
Softmax回归模型,该模型是logistic回归模型在多分类问题上的推广. 参考:http://blog.csdn.net/u014422406/article/details/52805924 ...
- “-bash: !”: event not found"、echo > sudo permission denied
1. "-bash: !": event not found" 比如当我们在 linux 命令行输入echo "Reboot your instance!&qu ...
- [转载]Surging Demo 项目之一
开发与运行环境 IDE Visual Stadio 2017/Visual Stadio 2019 Visual Stadio Core Docker 和 Docker-Compose 通过docke ...
- 量化交易中VWAP/TWAP算法的基本原理和简单源码实现(C++和python)(转)
量化交易中VWAP/TWAP算法的基本原理和简单源码实现(C++和python) 原文地址:http://blog.csdn.net/u012234115/article/details/728300 ...
- [Yarn] Use Yarn to Create an Alternative Import Name of an Installed Library
In this lesson we'll show how to use yarn to alias the names of same npm libraries but install diffe ...
- [Recompose] Add Local State with Redux-like Reducers using Recompose
Learn how to use the 'withReducer' higher order component using the alternative reducer form. If you ...