Problem:


Problem I: Most Distant Point from the Sea

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

Output for the Sample Input

5000.000000
494.233641
34.542948
0.353553



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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def cross2(p, q):
    return p[0]*q[1] - p[1]*q[0]
def cross3(o, p, q):
    return (p[0] - o[0])*(q[1] - o[1]) - (p[1] - o[1])*(q[0] - o[0])
def dot2(p, q):
    return p[0]*q[0] + p[1]*q[1]
def dist2(p):
    return p[0]**2 + p[1]**2
def segment_line_dist(x, p0, p1):
    z0 = (p1[0] - p0[0], p1[1] - p0[1])
    z1 = (x[0] - p0[0], x[1] - p0[1])
    if 0 <= dot2(z0, z1) <= dist2(z0):
        return abs(cross2(z0, z1)) / dist2(z0)**.5
    z2 = (x[0] - p1[0], x[1] - p1[1])
    return min(dist2(z1), dist2(z2))**.5

def polygon_cont(x, PS):
    V = [cross3(PS[i-1], PS[i], x) for i in range(len(PS))]
    return all(e >= 0 for e in V) or all(e <= 0 for e in V)
def polygon_dist(x, PS):
    return min(segment_line_dist(x, PS[i-1], PS[i]) for i in range(len(PS)))

def check(x, PS):
    if not polygon_cont(x, PS):
        return -polygon_dist(x, PS)
    return polygon_dist(x, PS)
def check_x(x, PS):
    ly = min(y for x, y in PS); ry = max(y for x, y in PS)
    EPS = 1e-6
    while ly + EPS < ry:
        y0 = (ly*2 + ry) / 3; y1 = (ly + ry*2) / 3
        if check((x, y0), PS) < check((x, y1), PS):
            ly = y0
        else:
            ry = y1
    return ly

def solve():
    N = int(readline())
    if N == 0:
        return False
    PS = [list(map(int, readline().split())) for i in range(N)]
    EPS = 1e-6
    lx = min(x for x, y in PS); rx = max(x for x, y in PS)
    while lx + EPS < rx:
        x0 = (lx*2 + rx) / 3; x1 = (lx + rx*2) / 3
        y0 = check_x(x0, PS); y1 = check_x(x1, PS)
        if check((x0, y0), PS) < check((x1, y1), PS):
            lx = x0
        else:
            rx = x1
    x0 = lx
    y0 = check_x(x0, PS)
    write("%.16f\n" % check((x0, y0), PS))
    return True
while solve():
    ...