Most Distant Point from the Sea
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 3476   Accepted: 1596   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

Source

模板题,没啥说的

求在多边形内,到边的距离最大的点

枚举半径,用半平面交判断

/* ***********************************************
Author :kuangbin
Created Time :2013/8/18 15:11:26
File Name :F:\2013ACM练习\专题学习\计算几何\半平面交\POJ3525.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const double eps = 1e-;
const double PI = acos(-1.0);
int sgn(double x)
{
if(fabs(x) < eps) return ;
if(x < ) return -;
else return ;
}
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,e;
double k;
Line(){}
Line(Point _s,Point _e)
{
s = _s; e = _e;
k = atan2(e.y - s.y,e.x - s.x);
}
Point operator &(const Line &b)const
{
Point res = s;
double t = ((s - b.s)^(b.s - b.e))/((s - e)^(b.s - b.e));
res.x += (e.x - s.x)*t;
res.y += (e.y - s.y)*t;
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.e - b.s)) < ;
}
Line Q[];
void HPI(Line line[], int n, Point res[], int &resn)
{
int tot = n;
sort(line,line+n,HPIcmp);
tot = ;
for(int i = ;i < n;i++)
if(fabs(line[i].k - line[i-].k) > eps)
line[tot++] = line[i];
int head = , tail = ;
Q[] = line[];
Q[] = line[];
resn = ;
for(int i = ; i < tot; i++)
{
if(fabs((Q[tail].e-Q[tail].s)^(Q[tail-].e-Q[tail-].s)) < eps || fabs((Q[head].e-Q[head].s)^(Q[head+].e-Q[head+].s)) < eps)
return;
while(head < tail && (((Q[tail]&Q[tail-]) - line[i].s)^(line[i].e-line[i].s)) > eps)
tail--;
while(head < tail && (((Q[head]&Q[head+]) - line[i].s)^(line[i].e-line[i].s)) > eps)
head++;
Q[++tail] = line[i];
}
while(head < tail && (((Q[tail]&Q[tail-]) - Q[head].s)^(Q[head].e-Q[head].s)) > eps)
tail--;
while(head < tail && (((Q[head]&Q[head-]) - Q[tail].s)^(Q[tail].e-Q[tail].e)) > eps)
head++;
if(tail <= head + )return;
for(int i = head; i < tail; i++)
res[resn++] = Q[i]&Q[i+];
if(head < tail - )
res[resn++] = Q[head]&Q[tail];
}
Point p[];
Line line[];
//*两点间距离
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
void change(Point a,Point b,Point &c,Point &d,double p)//将线段ab往左移动距离p
{
double len = dist(a,b);
double dx = (a.y - b.y)*p/len;
double dy = (b.x - a.x)*p/len;
c.x = a.x + dx; c.y = a.y + dy;
d.x = b.x + dx; d.y = b.y + dy;
}
Point pp[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
while(scanf("%d",&n) == && n)
{
for(int i = ;i < n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
double l = , r = ;
double ans = ;
while(r - l >= eps)
{
double mid = (l+r)/;
for(int i = ;i < n;i++)
{
Point t1,t2;
change(p[i],p[(i+)%n],t1,t2,mid);
line[i] = Line(t1,t2);
}
int resn;
HPI(line,n,pp,resn);
if(resn == )
r = mid - eps;
else
{
ans = mid;
l = mid + eps;
}
}
printf("%.6f\n",ans);
}
return ;
}

最新文章

  1. set和map的简单用法
  2. rpc框架之gRPC 学习 - hello world
  3. Linq to DataTable 左连接
  4. JAVA 处理程序异常,(try、catch、finally),(thorws)
  5. 浅谈 cookie 和 session
  6. css3 2d
  7. linux学习之centos(三):网卡配置
  8. jquery图片滑动联播效果
  9. Unable to find the ncurses libraries or the required header files解决
  10. Android Activity 常用功能设置(全屏、横竖屏等)
  11. 最近发现的.net core中的一些bugs
  12. 20170709_python_学习记录
  13. 安装php扩展 ffmpeg-php
  14. Notepad++ 64位 插件管理器 PluginManager 安装 更新
  15. openpyxl.utils.exceptions.IllegalCharacterError
  16. 工厂类,配置文件,静态方法,反射构成编译器解耦;ioc的一个概念 ;通过xml创建容器里面存储对象
  17. Mysql查询数据库 整理
  18. Hadoop2.2.0分布式安装配置详解[3/3]
  19. 帝国cms如何调用指定id的文章到首页?
  20. Aizu - 2681(括号匹配)

热门文章

  1. 关于&quot;轉淚點&quot;与&quot;轉捩點&quot;
  2. 以太坊go-ethereum客户端JSON-RPC API调用(一)
  3. web 端 gantt组件选型
  4. appium---【Mac】Appium-Doctor提示WARN:“ opencv4nodejs cannot be found”解决方案
  5. Cookie/Session的认识
  6. WPF 获取指定文件的Icon
  7. spring_150904_hibernatetemplate
  8. Codeforces Round #489 (Div. 2) E - Nastya and King-Shamans
  9. linux java环境变量设置
  10. Xamarin.Forms教程开发Xamarin.Forms应用程序需要的工具