Most Distant Point from the Sea

【题目链接】Most Distant Point from the Sea

【题目类型】半平面交

&题解:

蓝书279 二分答案,判断平移后的直线的半平面交是否为空.

模板是照着敲的,还有一些地方不是很懂, 应该还要慢慢体会吧

&代码:

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std; struct Point {
double x, y;
Point(double x = 0, double y = 0): x(x), y(y) {}
}; typedef Point Vector; Vector operator + (const Vector& A, const Vector& B) {return Vector(A.x + B.x, A.y + B.y);}
Vector operator - (const Vector& A, const Vector& B) {return Vector(A.x - B.x, A.y - B.y);}
Vector operator * (const Vector& A, double p) {return Vector(A.x * p, A.y * p);}
double Dot(const Vector& A, const Vector& B) {return A.x * B.x + A.y * B.y;}
double Cross(const Vector& A, const Vector& B) {return A.x * B.y - A.y * B.x;}
double Length(const Vector& A) {return sqrt(Dot(A, A));}
Vector Normal(const Vector& A) {double l = Length(A); return Vector(-A.y / l, A.x / l);} double PolygonArea(vector<Point> p) {
int n = p.size();
double s = 0;
for(int i = 1; i < n - 1; i++) {
s += Cross(p[i] - p[0], p[i + 1] - p[0]);
}
return s / 2;
} struct Line {
Point p, v;
double ang;
Line() {}
Line(Point p, Vector v): p(p), v(v) {ang = atan2(v.y, v.x);}
bool operator < (const Line& l) const {
return ang < l.ang;
}
}; bool OnLeft(const Line& L, const Point& p) {
return Cross(L.v, p - L.p) > 0;
} Point GetLineIntersection(const Line& a, const Line& b) {
Vector u = a.p - b.p;
double t = Cross(b.v, u) / Cross(a.v, b.v);
return a.p + a.v * t;
} const double eps = 1e-6;
vector<Point> HalfplaneIntersection(vector<Line> L) {
int n = L.size();
sort(L.begin(), L.end());
int first, last;
vector<Point> p(n), ans;
vector<Line> que(n);
que[first = last = 0] = L[0];
for(int i = 1; i < n; i++) {
while(first < last && !OnLeft(L[i], p[last - 1])) last--;
while(first < last && !OnLeft(L[i], p[first])) first++;
que[++last] = L[i];
if(fabs(Cross(que[last].v, que[last - 1].v)) < eps) {
last--;
if(OnLeft(que[last], L[i].p)) que[last] = L[i];
}
if(first < last) p[last - 1] = GetLineIntersection(que[last - 1], que[last]);
}
while(first < last && !OnLeft(que[first], p[last - 1])) last--;
if(last - first <= 1) return ans;
p[last] = GetLineIntersection(que[last], que[first]);
for(int i = first; i <= last; i++)
ans.push_back(p[i]);
return ans;
} int main() {
//("E:1.in", "r", stdin);
int n;
while(scanf("%d", &n) == 1 && n) {
vector<Vector> p, v, nor;
int m, x, y;
for(int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
p.push_back(Point(x, y));
}
if(PolygonArea(p) < 0) reverse(p.begin(), p.end());
for(int i = 0; i < n; i++) {
v.push_back(p[(i + 1) % n] - p[i]);
nor.push_back(Normal(v[i]));
}
double left = 0, right = 20000;
while(right - left > 1e-6) {
vector<Line> L;
double mid = left + (right - left) / 2;
for(int i = 0; i < n; i++)
L.push_back(Line(p[i] + nor[i]*mid, v[i]));
vector<Point> poly = HalfplaneIntersection(L);
if(poly.empty()) right = mid;
else left = mid;
}
printf("%f\n", left);
}
return 0;
}

LA 3890 Most Distant Point from the Sea(半平面交)的更多相关文章

  1. POJ 3525 Most Distant Point from the Sea [半平面交 二分]

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5153   ...

  2. POJ 3525 Most Distant Point from the Sea (半平面交)

    Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...

  3. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  4. POJ3525 Most Distant Point from the Sea(半平面交)

    给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...

  5. uvalive 3890 Most Distant Point from the Sea

    题意:求一个凸多边形中一点到边的最大距离. 思路:转换成在多边形内部,到每边距离为d的直线所围成的内多边形是否存在.也就是,二分距离+半平面交. #include<cstdio> #inc ...

  6. UVA 3890 Most Distant Point from the Sea(二分法+半平面交)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=11358 [思路] 二分法+半平面交 二分与海边的的距离,由法向量可 ...

  7. UVALive 3890 Most Distant Point from the Sea(凸包最大内接园)

    一个n个点的凸多边形,求多边形中离多边形边界最远的距离.实际上就是求凸包最大内接圆的半径. 利用半平面交求解,每次二分枚举半径d,然后将凸包每条边所代表的半平面沿其垂直单位法向量平移d,看所有平移后的 ...

  8. 【POJ】【3525】Most Distant Point from the Sea

    二分+计算几何/半平面交 半平面交的学习戳这里:http://blog.csdn.net/accry/article/details/6070621 然而这题是要二分长度r……用每条直线的距离为r的平 ...

  9. POJ 3525 Most Distant Point from the Sea (半平面交+二分)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3476   ...

随机推荐

  1. 深度学习中的batch的大小对学习效果的影响

    Batch_size参数的作用:决定了下降的方向 极端一: batch_size为全数据集(Full Batch Learning): 好处: 1.由全数据集确定的方向能够更好地代表样本总体,从而更准 ...

  2. 机器学习使用sklearn进行模型训练、预测和评价

    cross_val_score(model_name, x_samples, y_labels, cv=k) 作用:验证某个模型在某个训练集上的稳定性,输出k个预测精度. K折交叉验证(k-fold) ...

  3. 自动化运维工具-pdsh工具安装配置及简单使用讲解

    1.先决条件: 安装pssh工具的主机针对远程主机需要配置免秘钥认证: ssh-keygen -t rsa ssh-copy-id [remotehost] 2.下载pssh工具安装介质: https ...

  4. 最全最详细:ubuntu16.04下linux内核编译以及设备驱动程序的编写(针对新手而写)

    写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...

  5. android&sqlsever

    http://blog.csdn.net/chaoyu168/article/details/51910601

  6. [性能优化] perf 高级用法:完整记录程序性能指标,并按照时间段对程序进行有针对性的性能分析

    如题: 假设你已经熟悉了基本用法,知道perf是干嘛的,以及会用 perf top [性能优化] perf 背景:目标程序在运行的某时间段内会出现性能下降,需要了解这个时间内,程序发生了什么. 方法: ...

  7. OpenGL教程和书籍

    1.http://goanna.cs.rmit.edu.au/~gl/teaching/Interactive3D/

  8. scala-泛型

    //实例化之后使用get方法必须传入相同类型的参数 class A[T](x: T) { def get(x: T) { print(x) } } var a1 = new A(1) a1.get(1 ...

  9. java 选择排序、冒泡排序、折半查找

    public class SortAndSelectDemo{ public static void main(String[] args){ int[] arr = {3, 5, 17, 2, 11 ...

  10. 【PyQt5-Qt Designer】鼠标+键盘事件

    重定义鼠标响应+键盘响应事件 一,每个事件都被封装成相应的类: pyqt中,每个事件类型都被封装成相应的事件类,如鼠标事件为QMouseEvent,键盘事件为QKeyEvent等.而它们的基类是QEv ...