Problem:
Problem E: Roll-A-Big-Ball ACM University holds its sports day in every July. The "Roll-A-Big-Ball" 
is the highlight of the day.  In the game, players roll a ball
on a straight course drawn on the ground.  There are 
rectangular parallelepiped blocks on the ground as obstacles, which are fixed on the ground.
During the game, the ball may not collide with any blocks.
The bottom point of the ball may not leave the course. To have more fun, the university wants to use the largest possible ball
for the game.  You must
write a program that finds the largest radius of the ball that can reach
the goal without colliding any obstacle block. The ball is a perfect sphere, and the ground is a plane.
Each block is a rectangular parallelepiped.  The four edges of its bottom rectangle are on the ground, and parallel to either x- or y-axes. 
The course is given as a line segment from a start point to an end point.
The ball starts with its bottom point touching the start point, and goals when
its bottom point touches the end point. The positions of the ball and a block can be like in Figure E-1 (a) and (b).   Figure E-1: Possible positions of the ball and a block  Input The input consists of a number of datasets. 
Each dataset is formatted as follows.   N  sx  sy  ex  ey  minx 1  miny 1  maxx 1  maxy 1  h 1  minx 2  miny 2  maxx 2  maxy 2  h 2 ...  minx N  miny N  maxx N  maxy N  h N   A dataset begins with a line with an integer N , the number of
blocks (1 ≤ N ≤ 50). The next line consists of four integers,
delimited by a space,
indicating the start point ( sx , sy ) and the end point ( ex , ey ).

The following N lines give the placement of blocks. 
Each line, representing a block, consists of five integers delimited by a space.  These integers indicate the two vertices ( minx , miny ), ( maxx , maxy ) of the 
bottom surface and the height h of the block.




The integers sx , sy , ex , ey , minx , miny , maxx , maxy and h satisfy the following conditions. -10000 ≤ sx , sy , ex , ey ≤ 10000 -10000 ≤ minx i < maxx i ≤ 10000 -10000 ≤ miny i < maxy i ≤ 10000 1 ≤ h i ≤ 1000  The last dataset is followed by a line with a single zero in it. Output For each dataset, output a separate line containing the largest radius. 
You may assume that the largest radius never exceeds 1000 for each dataset.
If there are any blocks on the course line, the largest radius is defined to be zero.
The value may contain an error less than or equal to 0.001.
You may print any number of digits after the decimal point. Sample Input 2
-40 -40 100 30
-100 -100 -50 -30 1
30 -70 90 -30 10
2
-4 -4 10 3
-10 -10 -5 -3 1
3 -7 9 -3 1
2
-40 -40 100 30
-100 -100 -50 -30 3
30 -70 90 -30 10
2
-400 -400 1000 300
-800 -800 -500 -300 7
300 -700 900 -300 20
3
20 70 150 70
0 0 50 50 4
40 100 60 120 8
130 80 200 200 1
3
20 70 150 70
0 0 50 50 4
40 100 60 120 10
130 80 200 200 1
3
20 70 150 70
0 0 50 50 10
40 100 60 120 10
130 80 200 200 3
1
2 4 8 8
0 0 10 10 1
1
1 4 9 9
2 2 7 7 1
0 Output for the Sample Input 30
1
18.16666666667
717.7857142857
50.5
50
18.16666666667
0
0

Solution (Python):

from math import sqrt

def cross(P0, P1, P2):
    x0, y0 = P0; x1, y1 = P1; x2, y2 = P2
    x1 -= x0; x2 -= x0
    y1 -= y0; y2 -= y0
    return x1*y2 - x2*y1

def dot(P0, P1, P2):
    x0, y0 = P0; x1, y1 = P1; x2, y2 = P2
    x1 -= x0; x2 -= x0
    y1 -= y0; y2 -= y0
    return x1*x2 + y1*y2

def dist2(P0, P1):
    x0, y0 = P0; x1, y1 = P1
    return (x1 - x0)**2 + (y1 - y0)**2

def collision(S0, S1, T0, T1):
    return cross(S0, S1, T0)*cross(S0, S1, T1) < 0 and cross(T0, T1, S0) * cross(T0, T1, S1) < 0

def dist_lp(S, E, P):
    dd = dist2(S, E)
    
    if 0 <= dot(S, E, P) <= dd:
        
        return abs(cross(S, E, P))/sqrt(dd)
    
    return sqrt(min(dist2(S, P), dist2(E, P)))

def dist_ll(S0, S1, T0, T1):
    if collision(S0, S1, T0, T1):
        return 0
    return min(
            dist_lp(S0, S1, T0),
            dist_lp(S0, S1, T1),
            dist_lp(T0, T1, S0),
            dist_lp(T0, T1, S1)
            )

def contain(PS, A):
    l = len(PS)
    base = cross(PS[-1], PS[0], A)
    for i in range(l-1):
        P0 = PS[i]; P1 = PS[i+1]
        if base * cross(PS[i], PS[i+1], A) < 0:
            return 0
    return 1

c = 0
while 1:
    c += 1
    n = int(input())
    if n == 0:
        break
    sx, sy, ex, ey = map(int, input().split())
    S = sx, sy; E = ex, ey
    cannot = 0
    ans = 10**9
    for i in range(n):
        minx, miny, maxx, maxy, h = map(int, input().split())
        PS = ((minx, miny), (minx, maxy), (maxx, maxy), (maxx, miny))
        cannot |= contain(PS, S) or contain(PS, E)
        for j in range(4):
            cannot |= collision(PS[j-1], PS[j], S, E)
            d = dist_ll(S, E, PS[j-1], PS[j])
            ans = min(ans, (h**2+d**2)/(2*h) if h <= d else d)
    if cannot:
        print(0)
    else:
        print("%.08f" % ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def _kosa(a1, a2, b1, b2):
    x1,y1 = a1
    x2,y2 = a2
    x3,y3 = b1
    x4,y4 = b2

    tc = (x1-x2)*(y3-y1)+(y1-y2)*(x1-x3)
    td = (x1-x2)*(y4-y1)+(y1-y2)*(x1-x4)
    return tc*td < 0

def kosa(a1, a2, b1, b2):
    return _kosa(a1,a2,b1,b2) and _kosa(b1,b2,a1,a2)

def ky(p1, p2):
    return pow(pow(p1[0]-p2[0], 2) + pow(p1[1]-p2[1], 2), 0.5)

def distance3(p1, p2, p3):
    x1,y1 = p1
    x2,y2 = p2
    x3,y3 = p3

    ax = x2 - x1
    ay = y2 - y1
    bx = x3 - x1
    by = y3 - y1

    r = (ax*bx + ay*by) / (ax*ax + ay*ay)
    if r <= 0:
        return ky(p1, p3)
    if r >= 1:
        return ky(p2, p3)
    pt = (x1 + r*ax, y1 + r*ay, 0)
    return ky(pt, p3)


def main():
    rr = []

    def f(n):
        sx,sy,ex,ey = LI()
        sp = (sx,sy)
        ep = (ex,ey)
        a = [LI() for _ in range(n)]
        td = collections.defaultdict(lambda: inf)
        for x1,y1,x2,y2,h in a:
            ps = [(x1,y1), (x1,y2), (x2,y1), (x2,y2)]
            for p1,p2 in itertools.combinations(ps, 2):
                if kosa(sp,ep,p1,p2):
                    return 0
                for p in [sp,ep]:
                    dc = distance3(p1,p2,p)
                    if td[h] > dc:
                        td[h] = dc

            for p in ps:
                dc = distance3(sp,ep,p)
                if td[h] > dc:
                    td[h] = dc

        r = 1000
        for h,k in td.items():
            if k < h:
                if r > k:
                    r = k
                continue
            tr = 1.0 * (h**2 + k**2) / h / 2
            if r > tr:
                r = tr

        return '{:0.4f}'.format(r)

    while 1:
        n = I()
        if n == 0:
            break
        rr.append(f(n))
        

    return '\n'.join(map(str,rr))


print(main())

Solution (Python):
def cross(c1, c2):
    return c1.real * c2.imag - c1.imag * c2.real

def dot(c1, c2):
    return c1.real * c2.real + c1.imag * c2.imag

def ccw(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    cross_ab = cross(a, b)
    if cross_ab > 0:
        return 1
    elif cross_ab < 0:
        return -1
    elif dot(a, b) < 0:
        return 1
    elif abs(a) < abs(b):
        return -1
    else:
        return 0

def intersect(p1, p2, p3, p4):
    
    
    if (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0) and \
       (ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0):
        return True
    else:
        return False

def get_distance_sp(sp1, sp2, p):
    a = sp2 - sp1
    b = p - sp1
    if dot(a, b) < 0:
        return abs(b)
    c = sp1 - sp2
    d = p - sp2
    if dot(c, d) < 0:
        return abs(d)
    return abs(cross(a, b) / a)

def solve():
    from sys import stdin
    lines = stdin.readlines()
    
    while True:
        N = int(lines[0])
        if N == 0:
            break
        sx, sy, ex, ey = map(int, lines[1].split())
        sp = sx + sy * 1j
        ep = ex + ey * 1j
        R = []
        for l in lines[2:2+N]:
            D = []
            x1, y1, x2, y2, h = map(int, l.split())
            bp1 = x1 + y1 * 1j
            bp2 = x2 + y1 * 1j
            bp3 = x2 + y2 * 1j
            bp4 = x1 + y2 * 1j
            if intersect(sp, ep, bp1, bp2) or intersect(sp, ep, bp2, bp3) or \
            intersect(sp, ep, bp3, bp4) or intersect(sp, ep, bp4, bp1) or \
            (x1 <= sx <= x2 and y1 <= sy <= y2) or \
            (x1 <= ex <= x2 and y1 <= ey <= y2):
                print(0)
                break
            else:
                D.append(get_distance_sp(sp, ep, bp1))
                D.append(get_distance_sp(sp, ep, bp2))
                D.append(get_distance_sp(sp, ep, bp3))
                D.append(get_distance_sp(sp, ep, bp4))
                D.append(get_distance_sp(bp1, bp2, sp))
                D.append(get_distance_sp(bp1, bp2, ep))
                D.append(get_distance_sp(bp2, bp3, sp))
                D.append(get_distance_sp(bp2, bp3, ep))
                D.append(get_distance_sp(bp3, bp4, sp))
                D.append(get_distance_sp(bp3, bp4, ep))
                D.append(get_distance_sp(bp4, bp1, sp))
                D.append(get_distance_sp(bp4, bp1, ep))
                
                d = min(D)
                if h < d:
                    R.append((d ** 2 + h ** 2) / (2 * h))
                else:
                    R.append(d)
        else:
            print(min(R))
        lines = lines[2+N:]

solve()