poj3525Most Distant Point from the Sea【半平面交求到凸多边形边界最远距离】
来源:互联网 发布:网络恐怖主义案例 编辑:程序博客网 时间:2024/05/29 18:17
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.
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
40 010000 010000 100000 1000030 010000 07000 100060 40100 20250 40250 70100 900 7030 010000 100005000 50010
Sample Output
5000.000000494.23364134.5429480.353553
题意:给出日本岛为凸多边形顶点坐标求岛上到岛边界的最远距离;
半平面交+二分
#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#define eps 1e-10using namespace std;struct point{double x,y;}A[110],p[110],q[110];int N,tempcnt,endcnt;void guizheng(){for(int i=1;i<=N;++i){q[i]=A[N-i+1];}for(int i=1;i<=N;++i){A[i]=q[i];}}void getline(point p1,point p2,double &a,double &b,double &c){a=p2.y-p1.y;b=p1.x-p2.x;c=p2.x*p1.y-p2.y*p1.x;}void init(){for(int i=1;i<=N;++i){p[i]=A[i];}p[N+1]=p[1];p[0]=p[N];endcnt=N;}point getinter(point p1,point p2,double a,double b,double c){double u=fabs(a*p1.x+b*p1.y+c);double v=fabs(a*p2.x+b*p2.y+c);point temp;temp.x=(v*p1.x+u*p2.x)/(u+v);temp.y=(v*p1.y+u*p2.y)/(u+v);return temp;}void cut(double a,double b,double c){tempcnt=0;for(int i=1;i<=endcnt;++i){if(a*p[i].x+b*p[i].y+c>=0)q[++tempcnt]=p[i];else{if(a*p[i-1].x+b*p[i-1].y+c>0){q[++tempcnt]=getinter(p[i],p[i-1],a,b,c);}if(a*p[i+1].x+b*p[i+1].y+c>0)q[++tempcnt]=getinter(p[i],p[i+1],a,b,c);}}for(int i=1;i<=tempcnt;++i){p[i]=q[i];}p[tempcnt+1]=q[1];p[0]=p[tempcnt];endcnt=tempcnt;}bool solve(double r){init();for(int i=1;i<=N;++i){point ta,tb,tc;tc.x=A[i+1].y-A[i].y;tc.y=A[i].x-A[i+1].x;double k=r/sqrt(tc.x*tc.x+tc.y*tc.y);tc.x*=k;tc.y*=k;ta.x=A[i].x+tc.x;ta.y=A[i].y+tc.y;tb.x=A[i+1].x+tc.x;tb.y=A[i+1].y+tc.y;double a,b,c;getline(ta,tb,a,b,c);cut(a,b,c);}if(endcnt<=0)return false;return true;}int main(){int i,j,k;while(scanf("%d",&N),N){for(i=1;i<=N;++i){scanf("%lf%lf",&A[i].x,&A[i].y);}double left=0,right=200000000;guizheng();A[N+1]=A[1];while(left+eps<=right){double mid=(left+right)/2.0;if(solve(mid))left=mid;else right=mid;}printf("%lf\n",right);}return 0;}
- poj3525Most Distant Point from the Sea【半平面交求到凸多边形边界最远距离】
- POJ3525 Most Distant Point from the Sea(半平面交)
- poj 3525 Most Distant Point from the Sea - 求到海岸最远的点 - 半平面交
- LA3890 Most Distant Point from the Sea 多边形离边最远的点 半平面交,二分答案
- POJ 3525 Most Distant Point from the Sea(半平面交+二分)
- Poj 3525 Most Distant Point from the Sea (二分+半平面求交)
- POJ 3525 Most Distant Point from the Sea 半平面交 +二分
- poj 3525 Most Distant Point from the Sea(半平面交+二分)
- POJ 3525 Most Distant Point from the Sea 二分+半平面交
- poj 3525 Most Distant Point from the Sea(半平面交+二分内推进)
- POJ 3525 Most Distant Point from the Sea 二分+半平面交
- LA3890 Most Distant Point from the Sea 二分+半平面交
- poj 3525 Most Distant Point from the Sea 半平面交 + 二分
- poj 3525 Most Distant Point from the Sea,半平面交 + 二分
- 【二分+半平面交】 POJ 3525 Most Distant Point from the Sea
- POJ3525-Most Distant Point from the Sea(二分+半平面交)
- UVA 1396 Most Distant Point from the Sea(二分+半平面交)
- POJ 3525 Most Distant Point from the Sea 二分+半平面交
- metaq原理
- virt res shr 表示的意义
- JDBC1
- mac下pdo链接错误
- 员工管理Java
- poj3525Most Distant Point from the Sea【半平面交求到凸多边形边界最远距离】
- 风机桨叶故障诊断(六) 利用自编码器进行特征学习
- median of two sorted arrays
- JAVA1
- mysq中的子查询
- 面试题7:用两个栈实现队列
- UITableView的简单实用
- CentOS 6.5 与 win7 双系统时间同步问题
- 同步工具类-闭锁CountDownLatch