Fear of the Dark (Codeforces 1886B)
Tags: Math, geometry

Monocarp tries to get home from work. He is currently at the point $$$O = (0, 0)$$$ of a two-dimensional plane; his house is at the point $$$P = (P_x, P_y)$$$.Unfortunately, it is late in the evening, so it is very dark. Monocarp is afraid of the darkness. He would like to go home along a path illuminated by something.Thankfully, there are two lanterns, located in the points $$$A = (A_x, A_y)$$$ and $$$B = (B_x, B_y)$$$. You can choose any non-negative number $$$w$$$ and set the power of both lanterns to $$$w$$$. If a lantern's power is set to $$$w$$$, it illuminates a circle of radius $$$w$$$ centered at the lantern location (including the borders of the circle).You have to choose the minimum non-negative value $$$w$$$ for the power of the lanterns in such a way that there is a path from the point $$$O$$$ to the point $$$P$$$ which is completely illuminated. You may assume that the lanterns don't interfere with Monocarp's movement.  The picture for the first two test cases 

Input: The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.Each test case consists of three lines:  the first line contains two integers $$$P_x$$$ and $$$P_y$$$ ($$$-10^3 \le P_x, P_y \le 10^3$$$) — the location of Monocarp's house;  the second line contains two integers $$$A_x$$$ and $$$A_y$$$ ($$$-10^3 \le A_x, A_y \le 10^3$$$) — the location of the first lantern;  the third line contains two integers $$$B_x$$$ and $$$B_y$$$ ($$$-10^3 \le B_x, B_y \le 10^3$$$) — the location of the second lantern. Additional constraint on the input:  in each test case, the points $$$O$$$, $$$P$$$, $$$A$$$ and $$$B$$$ are different from each other. 

Output: For each test case, print the answer on a separate line — one real number equal to the minimum value of $$$w$$$ such that there is a completely illuminated path from the point $$$O$$$ to the point $$$P$$$.Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$ — formally, if your answer is $$$a$$$, and the jury's answer is $$$b$$$, your answer will be accepted if $$$\dfrac{|a - b|}{\max(1, b)} \le 10^{-6}$$$.


Sample Inputs:
2
3 3
1 0
-1 6
3 3
-1 -1
4 3

Sample Outputs:
3.6055512755
3.2015621187

Solution (Python):
import sys
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
    ans = 0
    (px, py) = map(int, sys.stdin.readline().rstrip().split())
    (ax, ay) = map(int, sys.stdin.readline().rstrip().split())
    (bx, by) = map(int, sys.stdin.readline().rstrip().split())
    mincentera = (ax ** 2 + ay ** 2) ** 0.5
    mincenterb = (bx ** 2 + by ** 2) ** 0.5
    minpa = ((px - ax) ** 2 + (py - ay) ** 2) ** 0.5
    minpb = ((px - bx) ** 2 + (py - by) ** 2) ** 0.5
    mind = ((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5 / 2
    center = 0
    p = 0
    if mincentera > mincenterb:
        center = 1
    if minpa > minpb:
        p = 1
    if center != p:
        if center == 0:
            ans = max(mincentera, minpb, mind)
        else:
            ans = max(mincenterb, minpa, mind)
    elif center == 0:
        ans = max(mincentera, minpa)
    else:
        ans = max(mincenterb, minpb)
    print(ans)

Solution (Python):
import sys
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
    ans = 0
    (px, py) = map(int, sys.stdin.readline().rstrip().split())
    (ax, ay) = map(int, sys.stdin.readline().rstrip().split())
    (bx, by) = map(int, sys.stdin.readline().rstrip().split())
    mincentera = (ax ** 2 + ay ** 2) ** 0.5
    mincenterb = (bx ** 2 + by ** 2) ** 0.5
    minpa = ((px - ax) ** 2 + (py - ay) ** 2) ** 0.5
    minpb = ((px - bx) ** 2 + (py - by) ** 2) ** 0.5
    mind = ((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5 / 2
    center = 0
    p = 0
    if mincentera > mincenterb:
        center = 1
    if minpa > minpb:
        p = 1
    if center != p:
        if center == 0:
            ans = max(mincentera, minpb, mind)
        else:
            ans = max(mincenterb, minpa, mind)
    elif center == 0:
        ans = max(mincentera, minpa)
    else:
        ans = max(mincenterb, minpb)
    print(ans)

Solution (Python):
import sys
import math
input = sys.stdin.readline

def inp():
    return int(input())

def inlt():
    return list(map(int, input().split()))

def insr():
    s = input()
    return list(s[:len(s) - 1])

def invr():
    return map(int, input().split())

def solve():
    (px, py) = invr()
    (ax, ay) = invr()
    (bx, by) = invr()
    O = [0, 0]
    P = [px, py]
    A = [ax, ay]
    B = [bx, by]
    if math.dist(P, A) < math.dist(P, B):
        mindisttop = math.dist(P, A)
        closesttop = A
    else:
        mindisttop = math.dist(P, B)
        closesttop = B
    if math.dist(O, A) < math.dist(O, B):
        mindisttoo = math.dist(O, A)
        closesttoo = A
    else:
        mindisttoo = math.dist(O, B)
        closesttoo = B
    W = max(mindisttop, mindisttoo)
    if closesttop == closesttoo:
        print(W)
        return
    elif math.dist(A, B) <= 2 * W:
        print(W)
        return
    else:
        print(W + (math.dist(A, B) - 2 * W) / 2)
        return
for t in range(inp()):
    solve()