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 (xi, yi)–(xi+1, yi+1) (1 ≤ in − 1) and the line segment (xn, yn)–(x1, y1) 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

题意:

给出一个凸包,求这个凸包里面某个点到边最远的距离

题解:

可以转化为内接圆的最大半径

此时我们可以将多边形缩小R,缩小后得到的刚好只有一个内核则这个R就是最远距离

#include<math.h>
#include<stdio.h>
#include<algorithm>
using namespace std;#define eps 1e-8
const int MAXN=2000;int n;
int cCnt,curCnt;///最终切割得到的多边形的顶点数、暂存顶点个数struct point
{double x,y;
};
point points[MAXN],p[MAXN],q[MAXN];///初始多边形顶点(顺时针)、最终切割后多边形顶点、暂存顶点void getline(point x,point y,double &a,double &b,double &c) ///两点x、y确定一条直线a、b、c为其系数
{a=y.y-x.y;b=x.x-y.x;c=y.x*x.y-x.x*y.y;
}
void initial()
{for(int i=1; i<=n; i++)p[i]=points[i];p[n+1]=p[1];p[0]=p[n];cCnt=n;
}
point intersect(point x,point y,double a,double b,double c)///点x、y所在直线与ax+by+c=0的交点
{double u=fabs(a*x.x+b*x.y+c);double v=fabs(a*y.x+b*y.y+c);point pt;pt.x=(x.x*v+y.x*u)/(u+v);pt.y=(x.y*v+y.y*u)/(u+v);return pt;
}
void cut(double a,double b,double c)
{curCnt=0;for(int i=1; i<=cCnt; i++){if(a*p[i].x+b*p[i].y+c>=0)///点代入线都大于0,说明此点都在这条直线某一边,不用切q[++curCnt]=p[i];else{if(a*p[i-1].x+b*p[i-1].y+c>0)///如果p[i-1]在直线的右侧的话q[++curCnt]=intersect(p[i],p[i-1],a,b,c);if(a*p[i+1].x+b*p[i+1].y+c>0)q[++curCnt]=intersect(p[i],p[i+1],a,b,c);}}for(int i=1; i<=curCnt; i++)p[i]=q[i];p[curCnt+1]=q[1];p[0]=p[curCnt];cCnt=curCnt;
}
int deal(double r)
{initial();for(int i=1;i<=n;i++)///向内缩进距离 r{point ta,tb,tt;tt.x=points[i+1].y-points[i].y;tt.y=points[i].x-points[i+1].x;double k=r/sqrt(tt.x * tt.x + tt.y * tt.y);tt.x=tt.x*k;tt.y=tt.y*k;ta.x=points[i].x + tt.x;ta.y=points[i].y + tt.y;tb.x=points[i+1].x + tt.x;tb.y=points[i+1].y + tt.y;double a,b,c;getline(ta,tb,a,b,c);cut(a,b,c);}return curCnt;
}
double solve()
{double left=0,right=100000000,mid;while(left+eps<right){mid=(left+right)/2.0;if(deal(mid)) left=mid;else right=mid;}return left;
}
void GuiZhengHua()
{///规整化方向,逆时针变顺时针,顺时针变逆时针for(int i=1;i<=n;i++) q[i]=points[n-i+1];for(int i=1;i<=n;i++) points[i]=q[i];
}
int main()
{freopen("in.txt","r",stdin);while(scanf("%d",&n)&&n){for(int i=1;i<=n;i++)scanf("%lf%lf",&points[i].x,&points[i].y);GuiZhengHua();points[n+1]=points[1];printf("%.6lf\n",solve());}return 0;
}

poj 3525 多边形内核,缩进相关推荐

  1. POJ3335(判断多边形内核是否存在)

    题目:Rotating Scoreboard 题意:题目要求判断多边形内核是否存在,若存在就输出YES,不存在就输出NO,本题和POJ1474一样.本题点的输入顺序是顺时针方向. /* Goujinp ...

  2. POJ1279(求多边形内核的面积)

    题目:Art Gallery 先求出内核,然后再求多边形的面积就行. /* Goujinping 2013.4.12 NEFU The masterplate of Polygon kernel. N ...

  3. poj 3525 tomo带鞘

    http://poj.org/problem?id=3525 转载于:https://www.cnblogs.com/ccccnzb/p/3945707.html

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

  5. poj 3082多边形相交 'Roid Rage

    题意是判断多边形是否相交 主要的思路就是判断每一个点是否在另外的多变形内 判断一个点是否在另一个多边形内主要思路是: 判断的那个点向左边做射线,如果射线与多边形的交点为奇数个则在多边形内,偶数个则不在 ...

  6. POJ 3525(计算几何+凸多边形最大内切圆)

    问题描述: The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it ...

  7. POJ 计算几何入门题目推荐

      其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中.之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途(例如本人的专 ...

  8. [Z]POJ 计算几何入门题目推荐[转PKKJ]

    http://www.cnblogs.com/eric-blog/archive/2011/05/31/2064785.html http://hi.baidu.com/novosbirsk/blog ...

  9. poj计算几何题推荐

    POJ 计算几何入门题目推荐(转)       其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中.之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的 ...

最新文章

  1. 算法导论——所有点对最短路径:稀疏图Johnson算法
  2. 【leetcode】
  3. 论林耐斯-Linux系统的重要性
  4. mysql之锁与事务
  5. fread和fwrite函数
  6. 分公司网络建设---Juniper 设备策略路由配置
  7. 利息高的贷款通过率会高一些吗?
  8. C#的正确版本号是多少?
  9. 2018-04-28
  10. “咏刚的家”全新改版
  11. 计算机组成原理期末复习整理 白中英版本
  12. Python爬虫:数据提取
  13. win pe备份linux,Windows10操作系统如何使用微PE实现备份与恢复
  14. Some file crunching failed, see logs for details
  15. 计算机评课用语不足与建议,信息技术评课要点
  16. 2017年进口食品代理加盟排行榜
  17. python遍历文件夹下的所有图片
  18. 10分钟搭建你的云端微信机器人️️️
  19. html5新特性有哪些?
  20. 抖音html啥意思,用了这么久的抖音,你知道抖音到底是啥意思吗?

热门文章

  1. 家里公司自动ip切换,批处理
  2. 7-4 有理数加法 (15 分)
  3. 基于linux的web自动化(selenium+jenkins+linux+firefox)
  4. 计算机与音乐制作专业就业前景,计算机音乐制作专业就业形势不错
  5. 机动车排放微观控制-汽油机内净化技术
  6. Android解析xml文件获取数据练习
  7. 老李分享:什么是好战略
  8. 硬件科普系列之硬盘——前言与准备知识篇
  9. 软件工程---总结与导图
  10. python中形参只在函数内部有效_【Python】函数