UVALive 3890 Most Distant Point from the Sea(凸包最大内接园)
一个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(凸包最大内接园)的更多相关文章
- uvalive 3890 Most Distant Point from the Sea
题意:求一个凸多边形中一点到边的最大距离. 思路:转换成在多边形内部,到每边距离为d的直线所围成的内多边形是否存在.也就是,二分距离+半平面交. #include<cstdio> #inc ...
- LA 3890 Most Distant Point from the Sea(半平面交)
Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- UVA 3890 Most Distant Point from the Sea(二分法+半平面交)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=11358 [思路] 二分法+半平面交 二分与海边的的距离,由法向量可 ...
- 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
二分+计算几何/半平面交 半平面交的学习戳这里: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 ...
- 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 ...
- POJ3525-Most Distant Point from the Sea(二分+半平面交)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3955 ...
随机推荐
- 【Demo 0004】Java基础-类封装性
本章学习要点: 1. Java封装特性; 2. 掌握类的定义: 3. 掌握类的调用方法; 一.封装特性 Java 纯面向对象语言,面向对象语言遵 ...
- java.util.zip - Recreating directory structure(转)
include my own version for your reference. We use this one to zip up photos to download so it works ...
- c中使用malloc动态申请二维数组
前言 今天写代码的时候,想要动态的申请一个二维数组空间,思索了一段时间才写出来,这里记录一下吧,以后就不至于再浪费时间了.下面以申请int型数组作为例子: 申请一维数组 一维数组的数组名可以看成数组起 ...
- html中的table在android端显示
转载请注明出处:http://blog.csdn.net/u012338845/article/details/46773245 開始都是用Html.fromHtml(source).来显示html的 ...
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- hdu 1028 母函数 一个数有几种相加方式
///hdu 1028 母函数 一个数有几种相加方式 #include<stdio.h> #include<string.h> #include<iostream> ...
- OCP读书笔记(1) - Oracle核心概念和工具
ohasdoracle high available service daemon OEMweb -- Database Control资料库 -- sysman Starting Oracle Re ...
- 端口映射工具 redir/socat/xinetd - 运维技术 - 开源中国社区
端口映射工具 redir/socat/xinetd - 运维技术 - 开源中国社区 端口映射工具 redir/socat/xinetd 10人收藏此文章, 我要收藏 发表于3天前(2013-08 ...
- POJ 3340 & HDU 2410 Barbara Bennett's Wild Numbers(数学)
题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Descript ...
- cocos2dx 制作单机麻将(一)
今天開始打算解说下cocos2dx下怎样制作国标麻将 前半部分先解说麻将的逻辑部分,由于都是代码,可能会比較枯燥无聊. 这部分讲完后,你也能够用其它游戏引擎来制作麻将 后半部分,就解说余下的cocos ...