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. [No0000F6]C# 继承

    继承是面向对象程序设计中最重要的概念之一.继承允许我们根据一个类来定义另一个类,这使得创建和维护应用程序变得更容易.同时也有利于重用代码和节省开发时间. 当创建一个类时,程序员不需要完全重新编写新的数 ...

  2. CM5.x配置spark错误解决

    通过cloudera manager 5.x添加spark服务,在创建服务过程中,发现spark服务创建失败,可以通过控制台错误输出看到如下日志信息: + perl -pi -e 's#{{CMF_C ...

  3. TIC Read Status此类网络活动提醒隐藏

    这个方法会使得NSLog输出失效,printf正常工作 不推荐使用,应该是很多操作均被关闭,需要详细了解该参数意义 OS_ACTIVITY_MODE = disable

  4. bilibili的直播第三方IJKMediaFramework.framework下载打包使用教程

    参考和引用的地址: http://www.code4app.com/thread-8941-1-1.html http://blog.csdn.net/cccallen/article/details ...

  5. MySQL transaction

    MySQL transaction(数据库的事务) 数据库事务(Database Transaction),是指作为单个逻辑工作单元执行的一系列操作. 要么完全执行,要么完全地不执行. ACID 事务 ...

  6. iOS程序main函数之前发生了什么

    我是前言 一个iOS app的main()函数位于main.m中,这是我们熟知的程序入口.但对objc了解更多之后发现,程序在进入我们的main函数前已经执行了很多代码,比如熟知的+ load方法等. ...

  7. LeetCode 897 Increasing Order Search Tree 解题报告

    题目要求 Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the r ...

  8. nginx最基本操作

    1.安装 yum install nginx 2.查看配置位置 nginx -t 3.查看nginx.conf,找到默认html配置路径 vi /etc/nginx/nginx.conf cd /us ...

  9. Git 常用命令和统计代码量

    摘要 分享Git日常操作中常用的命令,分享如何统计在项目中贡献的代码量. 下面列出Git bash常用命令. 1. git clone **(项目地址) 克隆一个git项目到本地,将git项目拉取到本 ...

  10. 使用natapp将本地服务映射到外网

    1.进入https://natapp.cn注册并登陆,然后下载客户端 2. 3. 4.打开客户端开启映射