题目传送门

题意:凸多边形的小岛在海里,问岛上的点到海最远的距离。

分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点。

/************************************************
* Author :Running_Time
* Created Time :2015/11/10 星期二 14:16:17
* File Name :LA_3890.cpp
************************************************/ #include <bits/stdc++.h>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);
int dcmp(double x) { //三态函数,减少精度问题
if (fabs (x) < EPS) return 0;
else return x < 0 ? -1 : 1;
}
struct Point { //点的定义
double x, y;
Point () {}
Point (double x, double y) : x (x), y (y) {}
Point operator + (const Point &r) const { //向量加法
return Point (x + r.x, y + r.y);
}
Point operator - (const Point &r) const { //向量减法
return Point (x - r.x, y - r.y);
}
Point operator * (double p) const { //向量乘以标量
return Point (x * p, y * p);
}
Point operator / (double p) const { //向量除以标量
return Point (x / p, y / p);
}
bool operator < (const Point &r) const { //点的坐标排序
return x < r.x || (x == r.x && y < r.y);
}
bool operator == (const Point &r) const { //判断同一个点
return dcmp (x - r.x) == 0 && dcmp (y - r.y) == 0;
}
};
typedef Point Vector; //向量的定义
Point read_point(void) { //点的读入
double x, y; scanf ("%lf%lf", &x, &y);
return Point (x, y);
}
double dot(Vector A, Vector B) { //向量点积
return A.x * B.x + A.y * B.y;
}
double cross(Vector A, Vector B) { //向量叉积
return A.x * B.y - A.y * B.x;
}
double length(Vector A) { //向量长度,点积
return sqrt (dot (A, A));
}
double polar_angle(Vector A) { //向量极角
return atan2 (A.y, A.x);
}
Vector nomal(Vector A) { //向量的单位法向量
double len = length (A);
return Vector (-A.y / len, A.x / len);
}
struct Line {
Point p;
Vector v;
double ang;
Line () {}
Line (const Point &p, const Vector &v) : p (p), v (v) {
ang = polar_angle (v);
}
bool operator < (const Line &r) const {
return ang < r.ang;
}
Point point(double a) {
return p + v * a;
}
}; bool point_on_left(Point p, Line L) {
return cross (L.v, p - L.p) > 0;
}
Point line_line_inter(Point p, Vector V, Point q, Vector W) { //两直线交点,参数方程
Vector U = p - q;
double t = cross (W, U) / cross (V, W);
return p + V * t;
} vector<Point> half_plane_inter(vector<Line> L) {
sort (L.begin (), L.end ());
int first, last, n = L.size ();
Point *p = new Point[n];
Line *q = new Line[n];
q[first=last=0] = L[0];
for (int i=1; i<n; ++i) {
while (first < last && !point_on_left (p[last-1], L[i])) last--;
while (first < last && !point_on_left (p[first], L[i])) first++;
q[++last] = L[i];
if (dcmp (cross (q[last].v, q[last-1].v)) == 0) {
last--;
if (point_on_left (L[i].p, q[last])) q[last] = L[i];
}
if (first < last) p[last-1] = line_line_inter (q[last-1].p, q[last-1].v, q[last].p, q[last].v);
}
while (first < last && !point_on_left (p[last-1], q[first])) last--;
vector<Point> ps;
if (last - first <= 1) return ps;
p[last] = line_line_inter (q[last].p, q[last].v, q[first].p, q[first].v);
for (int i=first; i<=last; ++i) ps.push_back (p[i]);
return ps;
} Point ps[110];
Vector V[110], V2[110]; int main(void) {
int n;
while (scanf ("%d", &n) == 1) {
if (!n) break;
for (int i=0; i<n; ++i) ps[i] = read_point ();
for (int i=0; i<n; ++i) {
V[i] = ps[(i+1)%n] - ps[i];
V2[i] = nomal (V[i]);
}
double l = 0, r = 20000;
while (r - l > EPS) {
double mid = l + (r - l) / 2;
vector<Line> L;
for (int i=0; i<n; ++i) {
L.push_back (Line (ps[i] + V2[i] * mid, V[i]));
}
vector<Point> qs = half_plane_inter (L);
int sz = qs.size ();
if (sz == 0) r = mid;
else l = mid;
}
printf ("%.6f\n", l);
} //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0;
}

  

简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea的更多相关文章

  1. LA 3890 Most Distant Point from the Sea(半平面交)

    Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...

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

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

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

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

  4. HDU 6617 Enveloping Convex(凸包+半平面交+二分)

    首先对于这m个点维护出一个凸包M,那么问题就变成了判断凸包P进行放大缩小能不能包含凸包M.(凸包P可以进行中心对称变换再进行放大缩小,见题意) 如何判断合适的相似比呢,我们可以用二分去放大缩小凸包P的 ...

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

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

  6. uvalive 3890 Most Distant Point from the Sea

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

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

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

  8. POJ 3525 半平面交+二分

    二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点 #include <cstdio> #include <cstring> # ...

  9. poj 2451 Uyuw's Concert (半平面交)

    2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...

随机推荐

  1. 交叉编译php5,、nginx、squid方法

    本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 交叉编译php5 软件版本:php-5.4.27 依赖库:zlib,libxml2 交叉编译器:arm-hisi ...

  2. HDU 4857 逃生 (优先队列+反向拓扑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4857 解题报告:有n个点,有m个条件限制,限制是像这样的,输入a  b,表示a必须排在b的前面,如果不 ...

  3. [Effective JavaScript 笔记]第60条:支持方法链

    无状态的API的部分能力是将复杂操作分解为更小的操作的灵活性.一个很好的例子是字符串的replace方法.由于结果本身也是字符串,可以对前一个replace操作重复执行替换.这种模式的一个常见用例是在 ...

  4. Linux 的shell 字符串截取很有用。有八种方法。

    一 Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.linuxidc.com/123.htm 1  # 号截取,删除左边字符,保留右边字符. echo ${va ...

  5. 利用nginx泛域名解析配置二级域名和多域名

    利用nginx泛域名解析配置二级域名和多域名 网站的目录结构为 html ├── bbs └── www html为nginx的安装目录下默认的存放源代码的路径. bbs为论坛程序源代码路径 www为 ...

  6. jquery取checkbox选中的值

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  7. 《C#高级编程》学习笔记------C#中的委托和事件(续)

    本文转载自张子阳 目录 为什么要使用事件而不是委托变量? 为什么委托定义的返回值通常都为void? 如何让事件只允许一个客户订阅?(事件访问器) 获得多个返回值与异常处理 委托中订阅者方法超时的处理 ...

  8. Light OJ 1253 Misere Nim (尼姆博弈(2))

    LightOJ1253 :Misere Nim 时间限制:1000MS    内存限制:32768KByte   64位IO格式:%lld & %llu 描述 Alice and Bob ar ...

  9. IncDec Sequence(codevs 2098)

    题目描述 Description 给定一个长度为n的数列{a1,a2...an},每次可以选择一个区间[l,r],使这个区间内的数都加一或者都减一. 问至少需要多少次操作才能使数列中的所有数都一样,并 ...

  10. makefile_1(初识make)

    Makefile有三个非常有用的变量.分别是$@,$^,$<代表的意义分别是: $@--目标文件,$^--所有的依赖文件,$<--第一个依赖文件. LIBS = -lmCFLAGS = - ...