POJ-3525 半平面交,二分答案

该问题要求编写程序,给定一个由凸多边形表示的岛屿地图,找出离海最远的点,并报告其距离。输入包含多个数据集,每个数据集代表一个岛屿,是一个简单且凸的多边形。程序需确保输出的距离精度在0.00001以内。
摘要由CSDN通过智能技术生成

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 (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<string.h>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e5+7;
const int maxp=2e3+7;
const double inf=1e200;
const double eps=1e-6;
const double pi =acos(-1.0);
int sgn(double x){
   
	if(fabs(x)<eps)return 0;
	return x>0?1:-1;
}
double hypot(double x,double y){
   return sqrt(x*x+y*y);}
struct Point{
   
	double x,y;
	Point(double x=0,double y=0):x(x),y(y){
   }
	bool operator ==(const Point& b){
   return !sgn(x-b.x)&&!sgn(y-b.y);}
	bool operator  <(const Point& b)const{
   return !sgn(x-b.x)?y<b.y:x<b.x;}
	double operator ^(const Point& b){
   return x*b.y-y*b.x;}//叉积
	double operator *(const Point& b){
   return x*b.x+y*b.y;}//点积
	Point operator +(const Point &b){
   return Point(x+b.x,y+b.y);}
	Point operator -(const Point& b){
   return Point(x-b.x,y-b.y);}
	Point operator *(const double &k){
   return Point(x*k,y*k);}
	Point operator /(const double &k){
   return Point(x/k,y/k);}
	double len(){
   return hypot(x,y);}
	double len2(){
   return x*x+y*y;}
	double rad(Point a,Point b){
   Point p=*this;return fabs(atan2(fabs((a-p)^(b-p)),(a-p)*(b-p)));}//pa和pb夹角
	double angle(){
   return atan2(y,x);}//倾斜角
	double angle(Point B
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值