问题描述:

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 ≤ i ≤ n − 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

题目题意:题目给我们一个凸多边形,让我们求出最大内切圆的半径。

题目分析:凸多边形可以看出凸多边形的边(直线)的半平面的交,其实只要这个半平面的交存在,那么这个内切圆就存在,当半平面的交不存在的时候,内切圆就不存在了。(最后变成一个点)

因为是凸多边形的原因,我们可以通过判断凸多边形的核是否存在来判断。

我们平移凸多边形的各个边,直到核不存在了,平移的距离就是最大内切圆的半径。

代码如下:(半平面交的代码是模板代码)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;const double eps=1e-8;
const double inf=1e9;
const int MAXN=210;
int m;//保存多边形的点数
double r;//保存内移距离
int cCnt,curCnt;//此时cCnt为最终切割得到的多边形的顶点数、暂存顶点个数
struct point
{double x,y;
};
point points[MAXN],p[MAXN],q[MAXN];//读入的多边形的顶点(顺时针)、p为存放最终切割得到的多边形顶点的数组、暂存核的顶点
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 <= m; ++i)p[i] = points[i];p[m+1] = p[1];p[0] = p[m];cCnt = m;
}
point intersect(point x,point y,double a,double b,double c)
{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)q[++curCnt] = p[i];else{if(a*p[i-1].x + b*p[i-1].y + c > 0){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 dcmp(double x)
{if(fabs(x)<eps) return 0;else return x<0?-1:1;
}
void solve()
{initial();for(int i = 1; i <= m; ++i){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);}
}
void GuiZhengHua(){ //规整化方向,逆时针变顺时针,顺时针变逆时针for(int i = 1; i < (m+1)/2; i ++)swap(points[i], points[m-i]);
}
int main()
{while (scanf("%d",&m)!=EOF){if (m==0) break;for (int i=1;i<=m;i++)scanf("%lf%lf",&points[i].x,&points[i].y);GuiZhengHua();points[m+1]=points[1];double left=0,right=inf,mid;while ((right-left)>=eps) {//二分求半径mid=(left+right)/2.0;// cout<<1<<endl;r=mid;solve();if (cCnt<=0) right=mid;else left=mid;}printf("%.6f\n",left);}return 0;
}

POJ 3525(计算几何+凸多边形最大内切圆)相关推荐

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

  2. [凸多边形最大内切圆][半平面交]Most Distant Point from the Sea POJ3525

    The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is na ...

  3. poj 3525 tomo带鞘

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

  4. [Poj 2187] 计算几何之凸包(二) {更高效的算法}

    { 承上一节 继续介绍点集的凸包  (下文中所有凸包 若不做特殊说明均指点集的凸包) 这一节介绍相比更高效的算法 } ========================================= ...

  5. POJ 2954-Triangle(计算几何+皮克定理)

    题目地址:POJ 2954 题意:给出三角形的三个顶点,求内部格点的个数. 思路:形同POJ 1265. #include <stdio.h> #include <math.h> ...

  6. POJ 1265-Area(计算几何+皮克定理+多边形面积公式)

    题目地址:POJ 1265 题意:给定一个格点多边形,求出内部点数in,边上点数on,和面积S. 思路:运用的定理很多. 1.皮克定理:S=in+on/2-1,即in=(2*S+2-on)/2. 2. ...

  7. POJ - Euclid(计算几何)

    题目链接:http://poj.org/problem?id=3813 Time Limit: 1000MS Memory Limit: 65536K Description In one of hi ...

  8. POJ 1584 计算几何 凸包

    链接: http://poj.org/problem?id=1584 题意: 按照顺时针或逆时针方向输入一个n边形的顶点坐标集,先判断这个n边形是否为凸包. 再给定一个圆形(圆心坐标和半径),判断这个 ...

  9. poj 1269 计算几何

    题意:此题要处理给定的四个点,前两个点,后两个点分别构成一条直线,判断这两条直线是否重合,平行,相交,若相交,给出交点. 解题思路:可以用向量叉积判断是否重合和平行 重合:设第一个点和第二个点构成向量 ...

最新文章

  1. about ajax,About 4nf.org - Arvind Gupta | Ajaxify | The Ajax Plugin
  2. defaultdict python_python中defaultdict的用法详解
  3. scala 中List的简单使用
  4. 游戏外挂设计技术探讨
  5. 赛门铁克备份软件服务起不来_软件安全开发服务资质和信息系统灾难备份与恢复服务资质...
  6. php如何读取多个url文件,如何从PHP中的URL获取具有相同名称的多个参数
  7. 相对、绝对、固定定位,以及其层级关系和脱离文档流的影响
  8. MVC源码解析 - 配置注册 / 动态注册 HttpModule
  9. Android Activity绑定到Service
  10. 路由器修改hosts实现域名劫持
  11. 林子雨spark scala版编程小结
  12. 简单易懂,过程详述大整数进制转换
  13. 巴斯大学计算机科学研究生,巴斯大学计算机科学.pdf
  14. Hadoop安装配置
  15. python 几何教学_GEE学习笔记 八十三:【GEE之Python版教程十三】几何图形
  16. 计算机局域网切换,怎么进入别人电脑--局域网【详解】
  17. matlab数据整周期截断,凯塞窗四谱线插值FFT的电力谐波分析方法
  18. Excel VBA: 工作表(Sheet)浏览导航插件
  19. 向上沟通-管理你的上司
  20. [Practical.Vim(2012.9)].Drew.Neil.Tip04 学习摘要

热门文章

  1. SAP中的发票校验容差控制测试
  2. Appium+python自动化(十四)- 与Capability完美懈垢之解读(超详解)
  3. Android 11 变更及适配攻略
  4. c++程序从1加到10(详细讲解版)
  5. my fav html
  6. 英语中描写”人”的词语集萃
  7. 数字IC前端面试问题总结
  8. 一个UDP用户数据报的首部的十六进制表示是06 32 00 45 00 1C E2 17。求源端口、目的端口、用户数据报总长度、数据部分长度。
  9. 搭建Iconic+angular混合APP开发环境
  10. 物联网还有哪些创业机会?