Most Distant Point from the Sea
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 4758   Accepted: 2178   Special Judge

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
/*
poj 3525 凸多边形多大内切圆 给你一个凸多边形的小岛地图,求出岛中到海岸线的最远距离。
相当于求多边形中最大的内切圆的半径,但是想了很久并没有发现什么方法 卒 问题可以转化成能够在多边形中找到一个圆。也就是二分多边形缩小的长度,然后
判断当前能否找到一个圆。
如果存在一个圆的话,那么它的圆心肯定是这个凸多边形的核。所以可以通过二分
和半平面相交判断解决
hhh-2016-05-11 22:10:56
*/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
using namespace std;
const int maxn = 1510;
const double PI = 3.1415926;
const double eps = 1e-8; int sgn(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0)
return -1;
else
return 1;
} struct Point
{
double x,y;
Point() {}
Point(double _x,double _y)
{
x = _x,y = _y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y-y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
}; struct Line
{
Point s,t;
double k;
Line() {}
Line(Point _s,Point _t)
{
s = _s;
t = _t;
k = atan2(t.y-s.y,t.x-s.x);
}
Point operator &(const Line &b) const
{
Point res = s;
double ta = ((s-b.s)^(b.s-b.t))/((s-t)^(b.s-b.t));
res.x += (t.x-s.x)*ta;
res.y += (t.y-s.y)*ta;
return res;
}
}; bool HPIcmp(Line a,Line b)
{
if(fabs(a.k-b.k) > eps) return a.k<b.k;
return ((a.s-b.s)^(b.t-b.s)) < 0;
}
Line li[maxn]; double CalArea(Point p[],int n)
{
double ans = 0;
for(int i = 0; i < n; i++)
{
ans += (p[i]^p[(i+1)%n])/2;
}
return ans;
} void HPI(Line line[],int n,Point res[],int &resn)
{
int tot =n;
sort(line,line+n,HPIcmp);
tot = 1;
for(int i = 1; i < n; i++)
{
if(fabs(line[i].k - line[i-1].k) > eps)
line[tot++] = line[i];
}
int head = 0,tail = 1;
li[0] = line[0];
li[1] = line[1];
resn = 0;
for(int i = 2; i < tot; i++)
{
if(fabs((li[tail].t-li[tail].s)^(li[tail-1].t-li[tail-1].s)) < eps||
fabs((li[head].t-li[head].s)^(li[head+1].t-li[head+1].s)) < eps)
return;
while(head < tail && (((li[tail] & li[tail-1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps)
tail--;
while(head < tail && (((li[head] & li[head+1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps)
head++;
li[++tail] = line[i];
}
while(head < tail && (((li[tail] & li[tail-1]) - li[head].s) ^ (li[head].t-li[head].s)) > eps)
tail--;
while(head < tail && (((li[head] & li[head-1]) - li[tail].s) ^ (li[tail].t-li[tail].t)) > eps)
head++;
if(tail <= head+1)
return;
for(int i = head; i < tail; i++)
res[resn++] = li[i]&li[i+1];
if(head < tail-1)
res[resn++] = li[head]&li[tail];
}
Point p0;
Point lis[maxn];
Line line[maxn];
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
} bool cmp(Point a,Point b)
{
double t = (a-p0)^(b-p0);
if(sgn(t) > 0)return true;
else if(sgn(t) == 0 && sgn(dist(a,lis[0])-dist(b,lis[0])) <= 0)
return true;
else
return false;
} Point ta,tb;
Point fans[maxn];
void fin(Point a,Point b,double mid)
{
double len = dist(a,b);
double dx = (a.y-b.y)*mid/len;
double dy = (b.x-a.x)*mid/len;
ta.x = a.x+dx,ta.y = a.y+dy;
tb.x = b.x+dx,tb.y = b.y+dy;
} int main()
{
//freopen("in.txt","r",stdin);
int n,T;
while(scanf("%d",&n)!= EOF && n)
{
for(int i = 0; i < n; i++)
{
scanf("%lf%lf",&lis[i].x,&lis[i].y);
}
int ans;
double l=0,r=100000;
double tans = 0;
while(r - l > eps)
{
double mid = (l+r) /2;
for(int i = 0; i < n; i++)
{
fin(lis[i],lis[(i+1)%n],mid);
line[i] = Line(ta,tb);
}
HPI(line,n,fans,ans);
if(ans)
l = mid+eps,tans = mid;
else
r = mid-eps;
}
printf("%.6f\n",tans);
}
return 0;
}

  

poj 3525 凸多边形多大内切圆的更多相关文章

  1. POJ 3525 Most Distant Point from the Sea

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

  2. poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】

    <题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...

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

  4. poj 3525

    多边形内最大半径圆. 哇没有枉费了我自闭了这么些天,大概五天前我看到这种题可能毫无思路抓耳挠腮举手投降什么的,现在已经能1A了哇. 还是先玩一会计算几何,刷个几百道 嗯这个半平面交+二分就阔以解决.虽 ...

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

  6. 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)

    按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...

  7. POJ 3525 半平面交+二分

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

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

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

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

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

随机推荐

  1. Python 科学计算-介绍

    Python 科学计算 作者 J.R. Johansson (robert@riken.jp) http://dml.riken.jp/~rob/ 最新版本的 IPython notebook 课程文 ...

  2. 利用Python爬取新浪微博营销案例库并下载到本地

    from bs4 import BeautifulSoup import requests,urllib.request,urllib.parse import json import time im ...

  3. 第九条:覆盖equals方法时总要覆盖hashCode方法

    Object类的hashCode方法: public native int hashCode();   是一个本地方法. 其中这个方法的主要注释如下: Whenever it is invoked o ...

  4. .Net Core SignalR 实时推送信息

    以前一直没用成功过SignalR(.net asp),最近几天又参考了对应的文档,最终调成功啦. 开始之前,应该注意: 一定要.Net Core 2.1.0以上的SDK. VS2017 15.6以上的 ...

  5. Css之导航栏下拉菜单

    Css: /*下拉菜单学习-2017.12.17 20:17 added by ldb*/ ul{ list-style-type:none; margin:; padding:; overflow: ...

  6. ajax的原理解析

    一.关于同步与异步的分析: 异步传输是面向字符的传输,它的单位是字符:而同步传输是面向比特的传输,它的单位是桢,它传输的时候要求接受方和发送方的时钟是保持一致的.而ajax就是采用的异步请求方式的. ...

  7. Spark学习笔记之RDD中的Transformation和Action函数

    总算可以开始写第一篇技术博客了,就从学习Spark开始吧.之前阅读了很多关于Spark的文章,对Spark的工作机制及编程模型有了一定了解,下面把Spark中对RDD的常用操作函数做一下总结,以pys ...

  8. Struts2 之值栈

    值栈(ValueStack) http://www.cnblogs.com/bgzyy/p/8639893.html 这是我的有关 struts2 的第一篇文章,对于里面我们说到的一个 struts2 ...

  9. JavaScript简单重写构造器的原型

    //简单重写原型对象: //一个构造函数Person function Person(){ } //重写Person的原型 //把Person的原型赋值给一个新的对象 是我们重写的过程 Person. ...

  10. mysql的账户管理

    mysql中账户管理:1 查看所有用户: 所有用户及权限信息都存储在mysql数据库中的user表中 查看user表的结构 desc user\G; 主要字段: host: 表示允许访问的主机 use ...