Description

The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is natural to ask a question: “Where is the most distant point from the sea?” The answer to this question for Honshu was found in 1996. The most distant point is located in former Usuda Town, Nagano Prefecture, whose distance from the sea is 114.86 km.

In this problem, you are asked to write a program which, given a map of an island, finds the most distant point from the sea in the island, and reports its distance from the sea. In order to simplify the problem, we only consider maps representable by convex polygons.

Input

The input consists of multiple datasets. Each dataset represents a map of an island, which is a convex polygon. The format of a dataset is as follows.

n    
x1   y1
   
xn   yn

Every input item in a dataset is a non-negative integer. Two input items in a line are separated by a space.

n in the first line is the number of vertices of the polygon, satisfying 3 ≤ n ≤ 100. Subsequent n lines are the x- and y-coordinates of the n vertices. Line segments (xiyi)–(xi+1yi+1) (1 ≤ i ≤ n − 1) and the line segment (xnyn)–(x1y1) form the border of the polygon in counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. All coordinate values are between 0 and 10000, inclusive.

You can assume that the polygon is simple, that is, its border never crosses or touches itself. As stated above, the given polygon is always a convex one.

The last dataset is followed by a line containing a single zero.

Output

For each dataset in the input, one line containing the distance of the most distant point from the sea should be output. An output line should not contain extra characters such as spaces. The answer should not have an error greater than 0.00001 (10−5). You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.

Sample Input

4
0 0
10000 0
10000 10000
0 10000
3
0 0
10000 0
7000 1000
6
0 40
100 20
250 40
250 70
100 90
0 70
3
0 0
10000 10000
5000 5001
0

Sample Output

5000.000000
494.233641
34.542948
0.353553 转载:http://blog.csdn.net/non_cease/article/details/7814970

题意:给定一个凸多边形,求多边形中距离边界最远的点到边界的距离。

思路 : 每次将凸多边形每条边往里平移d,判断是否存在核;二分d即可。

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std; const double eps = 1e-;
const int maxn = ; int dq[maxn], top, bot, pn, order[maxn], ln;
struct Point {
double x, y;
} p[maxn]; struct Line {
Point a, b;
double angle;
} l[maxn], tmp[maxn]; int dblcmp(double k) {
if (fabs(k) < eps) return ;
return k > ? : -;
} double multi(Point p0, Point p1, Point p2) {
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
} bool cmp(int u, int v) {
int d = dblcmp(l[u].angle-l[v].angle);
if (!d) return dblcmp(multi(l[u].a, l[v].a, l[v].b)) > ;
return d < ;
} void getIntersect(Line l1, Line l2, Point& p) {
double dot1,dot2;
dot1 = multi(l2.a, l1.b, l1.a);
dot2 = multi(l1.b, l2.b, l1.a);
p.x = (l2.a.x * dot2 + l2.b.x * dot1) / (dot2 + dot1);
p.y = (l2.a.y * dot2 + l2.b.y * dot1) / (dot2 + dot1);
} bool judge(Line l0, Line l1, Line l2) {
Point p;
getIntersect(l1, l2, p);
return dblcmp(multi(p, l0.a, l0.b)) < ;
} void addLine(double x1, double y1, double x2, double y2) {
l[ln].a.x = x1; l[ln].a.y = y1;
l[ln].b.x = x2; l[ln].b.y = y2;
l[ln].angle = atan2(y2-y1, x2-x1);
ln++;
} bool halfPlaneIntersection(Line l[], int n) {
int i, j;
for (i = ; i < n; i++) order[i] = i;
sort(order, order+n, cmp);
for (i = , j = ; i < n; i++)
if (dblcmp(l[order[i]].angle-l[order[j]].angle) > )
order[++j] = order[i];
n = j + ;
dq[] = order[];
dq[] = order[];
bot = ;
top = ;
for (i = ; i < n; i++) {
while (bot < top && judge(l[order[i]], l[dq[top-]], l[dq[top]])) top--;
while (bot < top && judge(l[order[i]], l[dq[bot+]], l[dq[bot]])) bot++;
dq[++top] = order[i];
}
while (bot < top && judge(l[dq[bot]], l[dq[top-]], l[dq[top]])) top--;
while (bot < top && judge(l[dq[top]], l[dq[bot+]], l[dq[bot]])) bot++;
if (bot + >= top) return false; //当dq中少于等于两条边时,说明半平面无交集
return true;
} double getDis(Point a, Point b) {
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} void changePolygon(double h) { //每次将直线向里面平移距离h
double len, dx, dy;
for (int i = ; i < ln; i++) {
len = getDis(l[i].a, l[i].b);
dx = (l[i].a.y - l[i].b.y) / len * h;
dy = (l[i].b.x - l[i].a.x) / len * h;
tmp[i].a.x = l[i].a.x + dx;
tmp[i].a.y = l[i].a.y + dy;
tmp[i].b.x = l[i].b.x + dx;
tmp[i].b.y = l[i].b.y + dy;
tmp[i].angle = l[i].angle;
}
} double BSearch() {
double l = , r = , mid;
while (l + eps < r) {
mid = (l + r) / ;
changePolygon(mid);
if (halfPlaneIntersection(tmp, ln))
l = mid;
else r = mid;
}
return l;
} int main()
{
int i; while (scanf ("%d", &pn) && pn) {
for (i = ; i < pn; i++)
scanf ("%lf%lf", &p[i].x, &p[i].y);
for (i = ln = ; i < pn-; i++)
addLine(p[i].x, p[i].y, p[i+].x, p[i+].y);
addLine(p[i].x, p[i].y, p[].x, p[].y); printf ("%.6lf\n", BSearch());
}
return ;
}

POJ 3525 Most Distant Point from the Sea (半平面交)的更多相关文章

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

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

  2. POJ 3525 Most Distant Point from the Sea

    http://poj.org/problem?id=3525 给出一个凸包,要求凸包内距离所有边的长度的最小值最大的是哪个 思路:二分答案,然后把凸包上的边移动这个距离,做半平面交看是否有解. #in ...

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

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

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

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

  5. POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)

    题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...

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

    题目就是求多变形内部一点. 使得到任意边距离中的最小值最大. 那么我们想一下,可以发现其实求是看一个圆是否能放进这个多边形中. 那么我们就二分这个半径r,然后将多边形的每条边都往内退r距离. 求半平面 ...

  7. POJ3525 Most Distant Point from the Sea(半平面交)

    给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...

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

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

  9. 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 ...

随机推荐

  1. 将百分制转换为5分制的算法 Binary Search Tree ordered binary tree sorted binary tree Huffman Tree

    1.二叉搜索树:去一个陌生的城市问路到目的地: for each node, all elements in its left subtree are less-or-equal to the nod ...

  2. MATLAB 用 imresize() 函数缩小图象是 double 和 uint8 有差别

    今天发现一个奇怪的现象. 在用 imresize() 缩小图象时,如果图象时 double 格式的,缩小后会产生不连通的现象. 下面是原图: 对这张图象 img 做 simg = imresize(i ...

  3. 133、TensorFlow加载模型(二)

    # 选择哪个变量来保存和恢复 # 如果你没有传递任何的参数到tf.train.Saver() # 这个saver会处理计算图中所有的变量 # 每一个变量都被保存,保存的名字就是当初创建他们时候的名字 ...

  4. 使用python执行sql语句和外键解析

    一.下载并导入pymysql pip install pymysql && import pymysql db=pymysql.connect(host=) #如果报错host大概率因 ...

  5. Kubernetes 对象管理的三种方式

    Kubernetes 中文文档 1. Kubernetes 对象管理的三种方式对比 Kubernetes 中的对象管理方式,根据对象配置信息的位置不同可以分为两大类: 命令式:对象的参数通过命令指定 ...

  6. php编程怎么和mysql连接

    php连接mysql的方法: MySQLi - 面向对象 MySQLi - 面向过程 关闭连接 连接在脚本执行完后会自动关闭.你也可以使用以下代码来关闭连接: (MySQLi - 面向对象 MySQL ...

  7. java Semaphore信号灯

    Semaphore实现的功能就类似2个公用电话,假如有10个人要打电话:那么只能2个人占有电话,8个需要等待.当2个人中 的任何一个人让开后,其中等待的另外8个人中又有一个人可以使用了等待的8个人中可 ...

  8. [暑假集训Day1T3]新的开始

    新建一个虚拟节点后直接跑最小生成树即可,从虚拟节点往每个节点连的边权为每个点建发电站的代价,许多人的考场贪心策略是:先构建原图的最小生成树后找一个花费最小的地方建发电厂.但是这样做不对的地方在于:如果 ...

  9. C语言接口

    struct i_foo * foobar_foo(void); //返回接口指针struct foo_object * foo_create(struct i_foo *iface, void *d ...

  10. MySQL--19 MHA切换日志分析

    MHA切换检测日志分析 GTID模式 [root@db03 ~]# tail -f /etc/mha/manager.log #在MySQL select ping:2006上出错(MySQL服务器已 ...