一个n个点的凸多边形,求多边形中离多边形边界最远的距离。实际上就是求凸包最大内接圆的半径。

利用半平面交求解,每次二分枚举半径d,然后将凸包每条边所代表的半平面沿其垂直单位法向量平移d,看所有平移后的半平面的交集是否为空。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<bitset>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
#include<stack>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define eps 1e-10
using namespace std; struct Point
{
double x, y;
Point (double x=0, double y=0):x(x), y(y) {}
};
typedef Point Vector; Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); } bool operator < (const Point& a, const Point& b)
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
} int dcmp(double x)
{
if(fabs(x) < eps) return 0;
return x < 0 ? -1 : 1;
} bool operator == (const Point& a, const Point& b)
{
return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
} double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Angel(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
double Area2(Vector A, Vector B, Vector C) { return Cross(B-A, C-A); }
Vector Normal(Vector a) //a向量的垂直法向量
{
return Vector(-a.y/Length(a), a.x/Length(a));
} struct Line
{
Point p;
Vector 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;
}
}; //点p在半平面的左边
bool onLeft(Line L, Point p) { return Cross(L.v, p-L.p) > 0; }
//直线交点
Point GetIntersection(Line a, 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 int maxn = 200;
Point p[maxn], poly[maxn];
Line L[maxn];
Vector v[maxn], v2[maxn];
int n; //半平面交
Point pp[maxn];
Line qq[maxn];
int HalfplaneIntersection(Line* L, int n, Point* poly)
{
sort(L, L+n);
int first, last; qq[first=last=0] = L[0];
FF(i, 1, n)
{
while(first < last && !onLeft(L[i], pp[last-1])) last--;
while(first < last && !onLeft(L[i], pp[first])) first++;
qq[++last] = L[i];
if(fabs(Cross(qq[last].v, qq[last-1].v)) < eps)
{
last--;
if(onLeft(qq[last], L[i].p)) qq[last] = L[i];
}
if(first < last) pp[last-1] = GetIntersection(qq[last-1], qq[last]);
}
while(first < last && !onLeft(qq[first], pp[last-1])) last--;
if(last-first <= 1) return 0;
pp[last] = GetIntersection(qq[last], qq[first]); int m = 0;
FF(i, first, last+1) poly[m++] = pp[i];
return m;
} int main()
{
while(scanf("%d", &n), n)
{
REP(i, n) scanf("%lf%lf", &p[i].x, &p[i].y);
REP(i, n)
{
v[i] = p[(i+1)%n]-p[i];
v2[i] = Normal(v[i]);
}
double l=0, r=20000, mid;
while(r - l > eps)
{
mid = (l+r) / 2.0;
REP(i, n) L[i] = Line(p[i]+v2[i]*mid, v[i]);
int m = HalfplaneIntersection(L, n, poly);
if(!m) r=mid; else l=mid;
}
printf("%.6f\n", l);
}
return 0;
}

UVALive 3890 Most Distant Point from the Sea(凸包最大内接园)的更多相关文章

  1. uvalive 3890 Most Distant Point from the Sea

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. POJ 3525/UVA 1396 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 ...

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

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

随机推荐

  1. 14.2.5.1 Role of the .frm File for InnoDB Tables InnoDB .frm文件的作用

    14.2.5.1 Role of the .frm File for InnoDB Tables: 14.2.5.1 Role of the .frm File for InnoDB Tables I ...

  2. 【Demo 0005】Java基础-类继承性

    本章学习要点:       1.  了解Java继承特性;       2.  掌握继承实现方法;       3.  掌握override规则: 一.类继承特性       1.  继承定义:使用己 ...

  3. 怎么提高ArcGIS for Desktop10.x的性能

    Esri新公布了一篇提高ArcGIS for Desktop10.x的性能的文章.大家能够关注一下 http://support.esri.com/en/knowledgebase/techartic ...

  4. Spring核心技术

    这是第二次看关于Spring的资料,由于刚開始学习Spring的时候是边看视频边学习的,所以更注重的是实现代码,可是对宏观的掌握还是不够,这次主要从宏观的角度来分析一下Spring. 什么是Sprin ...

  5. javascript (六) 引用外部js文件

    外部的 JavaScript 也可以把脚本保存到外部文件中.外部文件通常包含被多个网页使用的代码. 外部 JavaScript 文件的文件扩展名是 .js. 如需使用外部文件,请在 <scrip ...

  6. NET5

    ASP.NET5(RC1) - 翻译 前言 ASP.NET 5 是一次令人惊叹的对于ASP.NET的创新革命. 他将构建目标瞄准了 .NET Core CLR, 同时ASP.NET又是对于云服务进行优 ...

  7. 300M无线路由器 TL-WR842N - TP-LINK官方网站

    300M无线路由器 TL-WR842N - TP-LINK官方网站 300M无线路由器TL-WR842N 11N无线技术.300Mbps无线速率 2x2MIMO架构.CCA技术,提升无线稳定性.扩大无 ...

  8. Memcached 群集高可用性(HA)架构

    Memcache本身并不实现集群功能.假设你想使用Memcahce集群需要使用第三方软件或编程来实现自己的设计,这里将被用来memagent实现代理,memagent也被称为magent.我们注意到, ...

  9. 如何下载和编译Android4.0内核源代码goldfish(图像)

    如何下载Android4.0源代码.请参阅我的博客文章中有(同样是图文教程): http://blog.csdn.net/flydream0/article/details/7036156 怎样编译A ...

  10. 不显示系统错误对话框SetErrorMode(要学会搜索)

    关闭程序时报dde server window错误有人碰到过吗,用的别人的一个OCX控件,把这个控件去掉就不会报这个错误 //不显示系统错误对话框 SetErrorMode(SEM_NOGPFAULT ...