https://www.luogu.org/problemnew/show/P1663

给定山的性状,求一个最低点可以看见所有的地方。

就是半平面交。

粘贴全家福:

```cpp
#include
using namespace std;
typedef long long ll;

//不要输出-0.0之类的数

const double eps=1e-8;

const double inf=1e9;

const double pi=acos(-1.0); //小数点后15位精度,和atan2相同

//判断浮点数的符号

inline int cmp(double x) {

return (fabs(x)<eps)?0:((x>0.0)?1:-1);

}

inline double sqr(double x) {

return x*x;

}

struct Point {

double x,y;

Point() {};

Point(const double x,const double y):x(x),y(y) {};

friend Point operator+(const Point &a,const Point &b) {
return Point(a.x+b.x,a.y+b.y);
}
friend Point operator-(const Point &a,const Point &b) {
return Point(a.x-b.x,a.y-b.y);
}
friend Point operator*(const Point &p,const double k) {
return Point(p.x*k,p.y*k);
}
friend Point operator*(const double k,const Point &p) {
return Point(p.x*k,p.y*k);
}
friend Point operator/(const Point &p,const double k) {
return Point(p.x/k,p.y/k);
}
inline double angle() {
//返回向量的倾斜角,[-pi, pi]
return atan2(y,x);
}

};

double det(const Point &a,const Point &b) {

return a.xb.y-a.yb.x;

}

double dot(const Point &a,const Point &b) {

return a.xb.x+a.yb.y;

}

//半平面交,O(nlogn)

vector halfplane_intersection(vector v) {

sort(v.begin(),v.end(),compare);

deque q;

deque ans;

q.push_back(v[0]);

int vs=v.size();
for(int i=1;i<vs;++i){
if(cmp((v[i].second-v[i].first).angle()-(v[i-1].second-v[i-1].first).angle())==0)
continue;
while(!ans.empty()&&!satisfy(ans.back(),v[i])){
ans.pop_back();
q.pop_back();
}
while(!ans.empty()&&!satisfy(ans.front(),v[i])){
ans.pop_front();
q.pop_front();
}
ans.push_back(intersect_point(q.back(),v[i]));
q.push_back(v[i]);
}
while(!ans.empty()&&!satisfy(ans.back(),q.front())){
ans.pop_back();
q.pop_back();
}
while(!ans.empty()&&!satisfy(ans.front(),q.back())){
ans.pop_front();
q.pop_front();
}
ans.push_back(intersect_point(q.back(),q.front()));
return vector<Point>(ans.begin(),ans.end());

}

void solve() {

int n;

scanf("%d",&n);

double x[5005],y[5005];

for(int i=1;i<=n;i++){

scanf("%lf%lf",&x[i],&y[i]);

}

vector hp;

hp.push_back(Halfplane(Point(x[1],inf),Point(x[1],y[1])));

hp.push_back(Halfplane(Point(x[n],y[n]),Point(x[n],inf)));

hp.push_back(Halfplane(Point(x[n],inf),Point(x[1],inf)));

for(int i=2;i<=n;i++){

hp.push_back(Halfplane(Point(x[i-1],y[i-1]),Point(x[i],y[i])));

}

/*for(int i=0;i<(int)hp.size();i++){
printf("Point1 %d: (%.4f, %4f)\n",i+1,hp[i].first.x,hp[i].first.y);
printf("Point2 %d: (%.4f, %4f)\n",i+1,hp[i].second.x,hp[i].second.y); puts("");
}*/ double ans=inf;
vector<Point> hpi=halfplane_intersection(hp);
int hs=hpi.size();
for(int i=0;i<hs;i++){
//printf("Point %d: (%.4f, %4f)\n",i+1,hpi[i].x,hpi[i].y);
ans=min(ans,hpi[i].y);
}
printf("%8f\n",ans);

}

int main() {

ifdef Yinku

freopen("Yinku.in","r",stdin);

endif // Yinku

solve();
return 0;

}

<details>

洛谷 - P1663 - 山 - 半平面交的更多相关文章

  1. 洛谷 - P2283 - 多边形 - 半平面交

    https://www.luogu.org/problemnew/show/P2283 需要注意max是求解顺序是从右到左,最好保证安全每次都清空就没问题了. #include<bits/std ...

  2. 洛谷 P1663 山

    https://www.luogu.org/problemnew/show/P1663 可能在这里看会好一点:[题解]

  3. 洛谷P3222 [HNOI2012]射箭(计算几何,半平面交,双端队列)

    洛谷题目传送门 设抛物线方程为\(y=ax^2+bx(a<0,b>0)\),我们想要求出一组\(a,b\)使得它尽可能满足更多的要求.这个显然可以二分答案. 如何check当前的\(mid ...

  4. 【BZOJ-4515】游戏 李超线段树 + 树链剖分 + 半平面交

    4515: [Sdoi2016]游戏 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 304  Solved: 129[Submit][Status][ ...

  5. poj3335 半平面交

    题意:给出一多边形.判断多边形是否存在一点,使得多边形边界上的所有点都能看见该点. sol:在纸上随手画画就可以找出规律:按逆时针顺序连接所有点.然后找出这些line的半平面交. 题中给出的点已经按顺 ...

  6. POJ3525 半平面交

    题意:求某凸多边形内部离边界最远的点到边界的距离 首先介绍半平面.半平面交的概念: 半平面:对于一条有向直线,它的方向的左手侧就是它所划定的半平面范围.如图所示: 半平面交:多个半平面的交集.有点类似 ...

  7. POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交

    题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...

  8. bzoj2618[Cqoi2006]凸多边形 半平面交

    这是一道半平面交的裸题,第一次写半平面交,就说一说我对半平面交的理解吧. 所谓半平面交,就是求一大堆二元一次不等式的交集,而每个二元一次不等式的解集都可以看成是在一条直线的上方或下方,联系直线的标准方 ...

  9. POJ 3384 Feng Shui 半平面交

    题目大意:一个人很信"Feng Shui",他要在房间里放两个圆形的地毯. 这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面.求这两个地毯可以覆盖的最大范围.并输出这两个 ...

随机推荐

  1. 神经网络实现Discuz验证码识别

    最近自己尝试了网上的验证码识别代码项目,该小项目见以下链接: https://cuijiahua.com/blog/2018/01/dl_5.html 数据也就用了作者上传的60000张Discuz验 ...

  2. IOS8 TouchID使用介绍

    本文转载至 http://blog.csdn.net/jinkaiouyang/article/details/35555123 IOS8将指纹识别技术开放出来了.我们能够利用用户设置的touch I ...

  3. P1355 神秘大三角

    题目描述 判断一个点与已知三角形的位置关系. 输入输出格式 输入格式: 前三行:每行一个坐标,表示该三角形的三个顶点 第四行:一个点的坐标,试判断该点与前三个点围成三角形的位置关系 (详见样例) 所有 ...

  4. Machine Learning in Action(5) SVM算法

    做机器学习的一定对支持向量机(support vector machine-SVM)颇为熟悉,因为在深度学习出现之前,SVM一直霸占着机器学习老大哥的位子.他的理论很优美,各种变种改进版本也很多,比如 ...

  5. spring+mybatis项目整合

    前辈总结的很详细,贴出链接,参考学习 http://www.open-open.com/lib/view/open1392252233301.html

  6. user版本如何永久性开启adb 的root权限【转】

    本文转载自:http://blog.csdn.net/o0daxu0o/article/details/52933926 [Solution]* adb 的root 权限是在system/core/a ...

  7. 人生苦短之Python迭代器

     迭代 在Python中,如果给定一个list或者touple,我们可以通过for循环来遍历,将值依次取出,这种遍历称为迭代. 在Python中是通过for...in..来进行遍历的,在Java中则是 ...

  8. IOS开发学习笔记(2)-----UIButton 详解

    1. [代码][C/C++]代码     //这里创建一个圆角矩形的按钮    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRou ...

  9. tflearn 中文汉字识别,训练后模型存为pb给TensorFlow使用——模型层次太深,或者太复杂训练时候都不会收敛

    tflearn 中文汉字识别,训练后模型存为pb给TensorFlow使用. 数据目录在data,data下放了汉字识别图片: data$ ls0  1  10  11  12  13  14  15 ...

  10. 迁移学习算法之TrAdaBoost ——本质上是在用不同分布的训练数据,训练出一个分类器

    迁移学习算法之TrAdaBoost from: https://blog.csdn.net/Augster/article/details/53039489 TradaBoost算法由来已久,具体算法 ...