LA 3890 Most Distant Point from the Sea(半平面交)
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(半平面交)的更多相关文章
- POJ 3525 Most Distant Point from the Sea [半平面交 二分]
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5153 ...
- 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 ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- POJ3525 Most Distant Point from the Sea(半平面交)
给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...
- uvalive 3890 Most Distant Point from the Sea
题意:求一个凸多边形中一点到边的最大距离. 思路:转换成在多边形内部,到每边距离为d的直线所围成的内多边形是否存在.也就是,二分距离+半平面交. #include<cstdio> #inc ...
- UVA 3890 Most Distant Point from the Sea(二分法+半平面交)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=11358 [思路] 二分法+半平面交 二分与海边的的距离,由法向量可 ...
- UVALive 3890 Most Distant Point from the Sea(凸包最大内接园)
一个n个点的凸多边形,求多边形中离多边形边界最远的距离.实际上就是求凸包最大内接圆的半径. 利用半平面交求解,每次二分枚举半径d,然后将凸包每条边所代表的半平面沿其垂直单位法向量平移d,看所有平移后的 ...
- 【POJ】【3525】Most Distant Point from the Sea
二分+计算几何/半平面交 半平面交的学习戳这里:http://blog.csdn.net/accry/article/details/6070621 然而这题是要二分长度r……用每条直线的距离为r的平 ...
- POJ 3525 Most Distant Point from the Sea (半平面交+二分)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3476 ...
随机推荐
- shell之使用cut切割文本文件
我们知道可以通过工具grep或egrep按行筛选记录,这里我们可以通过cut工具对文本按列进行切分,它可以指定定界符,linux下制表符是默认的定界符. #cut -f 2,3 textfile 这个 ...
- mysql表引擎myisam改为innodb
1.进入数据库 2.SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements FROM ...
- DOM节点的基础操作
1.寻找节点 //寻找节点 id方法 document.getElementById(); //标准 //寻找节点层次方法 parentNode().firstChild()和lastChild(): ...
- ios -RunLoop(简单理解)
一. RunLoop简介 RunLoop字面意思是运行时,即跑圈得意思.它可以在我们需要的时候自己跑起来运行,在我们没有操作的时候就停下来休息,充分节省CPU资源,提高程序性能. 二. RunLoop ...
- mysql缓存分析
- [ovs][dpdk] ovs-dpdk 线程数,收包队列,core绑定
http://docs.openvswitch.org/en/latest/intro/install/dpdk/?highlight=dpdk 绑定2,4,6, 8核 [root@vrouter1 ...
- java之反射的基本介绍
什么是反射 JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法:这种动态获取的以及动态调用对象的方法的功能称为Java的反射 ...
- js 判断字符串长度
转载来处:https://www.cnblogs.com/hello321/p/7821400.html 第一种使用方法: var aa="1,2,3,4,5"; var bb=a ...
- GIt如何进行代码管理
一:Git账号设置(仅第一次需设置): 1.首先打开GIt Bash 界面
- 洛谷P3245 大数 [HNOI2016] 莫队
正解:莫队 解题报告: 传送门 这题首先要发现一个结论,是这样儿的: 若p不是10的约数(即2和5) 时,当第i位到第n位组成的数%p==第j位到第n位组成的数%p,那么第i位到第j位上的数组成的数% ...