poj 3525 多边形内核,缩进
来源:互联网 发布:java url重写技术 编辑:程序博客网 时间:2024/06/08 01:58
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.
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.
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 then 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.
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.
40 010000 010000 100000 1000030 010000 07000 100060 40100 20250 40250 70100 900 7030 010000 100005000 50010
5000.000000494.23364134.5429480.353553
题意:
给出一个凸包,求这个凸包里面某个点到边最远的距离
题解:
可以转化为内接圆的最大半径
此时我们可以将多边形缩小R,缩小后得到的刚好只有一个内核则这个R就是最远距离
#include<math.h>#include<stdio.h>#include<algorithm>using namespace std;#define eps 1e-8const 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 多边形内核,缩进
- POJ 1279 Art Gallery 多边形内核面积
- POJ 3335 Rotating Scoreboard(求解多边形内核)
- POJ 3335 Rotating Scoreboard 半平面交求多边形内核
- POJ 1279 Art Gallery (多边形组成的内核面积)
- POJ 1474 Video Surveillance (多边形内核判断)
- 求解多边形内核
- 内核风格缩进工具indent
- POJ 1474 Video Surveillance 半平面交求多边形内核存在性
- POJ 3130 How I Mathematician Wonder What You Are! (半平面交+多边形内核判断)
- POJ-1279 Art Gallery(求多边形内核面积,半平面交)
- poj 3335 Rotating Scoreboard(半平面交,求解多边形内核)
- poj 1389 多边形面积
- POJ 1654 多边形面积
- poj 1265 多边形面积
- POJ-1385 多边形重心
- poj 1654 多边形面积
- POJ-1750(缩进控制)
- 【golang】aws s3 go sdk
- [排序] 直接插入排序(Python)
- 如何下载通过 jitpack 发布的 jar
- centos 7 安装java redis
- html5 video 手机端视频播放全屏显示
- poj 3525 多边形内核,缩进
- 基础dp
- mybatis中llike模糊查询中#和$的使用
- yarn平台的内存分配和设置
- vue相关的开源项目
- 数据库索引的实现原理
- 创建私有Pods
- 简单易学的机器学习算法——Mean Shift聚类算法
- 浅谈三种特殊进程:孤儿进程,僵尸进程和守护进程