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 ...
随机推荐
- ATM JAVA实现 部分代码
package score;//信1705-2 20173600 王重阳 import java.util.Scanner; public class Main { public static voi ...
- 一些shell默认的变量
测试脚本如下,我这里主要想测试$0,$1,$2,$n,$@,$*默认都代表了什么? #!/bin/sh echo '$1='$1 echo '$2='$2 echo '$@='$@ echo '$*= ...
- A pointer is a variable whose value is the address of another variable 指针 null pointer 空指针 内存地址0 空指针检验
小结: 1.指针的实际值为代表内存地址的16进制数: 2.不同指针的区别是他们指向的变量.常量的类型: https://www.tutorialspoint.com/cprogramming/c_po ...
- 对内存分配的理解 自动变量 局部变量 临时变量 外部变量 字符串长度 C语言可以看成由一些列的外部对象构成
Status ListInsert_Sq(SqList *L,int i,LElemType_Sq e) { LElemType_Sq *newbase; LElemType_Sq *p,*q; if ...
- 关于ionic2 更新到ionic3 后组件不能用的解决方案
错误代码就不贴出来了,直接上代码吧! 首先在xx.module.ts添加 1.import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 2.添加 ...
- odoo10如何自定义自动生成单据编号
1.在已有的model中穿件一个字段name class qingjiadan(models.Model): _name = 'qingjia.qingjiadan' name = fields.Ch ...
- js数组方法汇总
下面主要汇总一下数组的方法 数组方法: 1.检测是否为数组的方法:Array.isArrray(); var arr=[1,2,3,4,5]; var str='string'; console.lo ...
- 简单的document操作
1.新增商品:新建文档,建立索引PUT /index/type/id{ "json数据"}例如:PUT /ecommerce/product/1{ "name" ...
- InnoDB Lock
众所周知innodb的锁是行级锁,这样说也没有问题,只是还可以细分而已.推荐阅读何登成大牛的博客http://hedengcheng.com/?p=771 innodb的锁有三种算法,分别如下: Re ...
- discuz优化10个小技巧
Discuz论坛是国内使用最多的论坛系统,现在最新版为X 3.4,X3.4 从 2018 年 1 月 1 日起只在官方 Git 发布,地址:https://gitee.com/ComsenzDiscu ...