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. 升级svn 到1.7

    sudo yum update sudo yum groupinstall "Development tools" sudo yum groupinstall "Addi ...

  2. spring 集成 mybatis 后数据源初始化失败问题分析

    问题背景: 项目使用spring,springmvc框架,后边需操作关系数据库,选择了mybatis + durid,集成mybatis后,项目一直启动失败.错误的原因是dataSource初始化的时 ...

  3. Hibernate表关系映射之多对多映射

    一.多对多的实现原理 在数据库中实现多对多的关系,必须使用连接表.也就是用一个独立的表来存入两个表的主键字段,通过遍历这张表来获取两表的关联关系. 而在我们的对象中,多对多是通过两者对象类中互相建立对 ...

  4. requests 中文乱码

    jsUrl = 'http://www.heze.cn/qiye/index.php?a=userinfo&username={}'.format(bizQiyeId)r = requests ...

  5. Nothing but the key 属性全部依赖于主键 third norm form

    全依赖 Designs that Violate 1NF CustomerCustomer ID First Name Surname Telephone Number123 Pooja Singh ...

  6. 安装mysql时,提示This application requires .NET framework 4.0问题

    Question:双击MySQL的安装文件, 弹框提示,   Answer:安装微软的 .NET Framework 4或更新的版本,下载地址:https://www.microsoft.com/zh ...

  7. 事件 MotionEvent

    点击和长按可能会同时发生,需要在长按的回调函数中返回true,就不会产生点击.谁处理事件谁就是消费者 如果view组件不处理事件,最后会让ontouchevent处理,它是备胎 <LinearL ...

  8. mtk6589显示子系统笔记(一)

    拿到MT6589的版本不久,发现显示系统代码结构改变很大.做些备忘,后续不忙的时候可以继续看. MT6589之前的MTK的Android系统显示系统同featurePhone基本一致. 先来回顾下MT ...

  9. java连接oracle的几种方式

    jdbc连接(驱动包ojdbc6.jar)String driver = "oracle.jdbc.OracleDriver"; //驱动标识符 String url = &quo ...

  10. Java丨时间判断谁前谁后

    直奔主题: String date_str1 = "2016-06-02 23:03:123"; String date_str2 = "2016-06-03 03:03 ...