Problem:


Score : 500 points

Problem Statement

   #nck {
      width: 30px;
      height: auto;
   }

Snuke received a triangle as a birthday present.
The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3).

He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch).
Compute the maximum possible radius of the circles.

Constraints

0 ≤ x_i, y_i ≤ 1000

The coordinates are integers.

The three points are not on the same line.

Input

The input is given from Standard Input in the following format:

x_1 y_1
x_2 y_2
x_3 y_3

Output

Print the maximum possible radius of the circles.
The absolute error or the relative error must be at most 10^{-9}.

Sample Input 1

0 0
1 1
2 0

Sample Output 1

0.292893218813

Sample Input 2

3 1
1 5
4 9

Sample Output 2

0.889055514217



Sample input:
0 0
1 1
2 0


Sample output:
0.292893218813

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque

def check(max_length, left, right, r, index):
    if index == 100:
        print(left)
    half = (left + right) / 2
    if 2 * half <= max_length * (r - half) / r:
        check(max_length, half, right, r, index + 1)
    else:
        check(max_length, left, half, r, index + 1)

def main():
    data = [list(map(int, input().split())) for i in range(3)]
    a = ((data[0][0] - data[1][0]) ** 2 + (data[0][1] - data[1][1]) ** 2) ** 0.5
    b = ((data[1][0] - data[2][0]) ** 2 + (data[1][1] - data[2][1]) ** 2) ** 0.5
    c = ((data[0][0] - data[2][0]) ** 2 + (data[0][1] - data[2][1]) ** 2) ** 0.5

    s = (a + b + c) / 2
    S = (s * (s - a) * (s - b) * (s - c)) ** 0.5
    r = 2 * S / (a + b + c)

    left, right = 0, max(a, b, c)

    check(max(a, b, c), left, right, r, 0)





if __name__ == '__main__':
    main()
    # test()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque

def check(max_length, left, right, r, index):
    if index == 1000:
        print(left)
    half = (left + right) / 2
    if 2 * half <= max_length * (r - half) / r:
        check(max_length, half, right, r, index + 1)
    else:
        check(max_length, left, half, r, index + 1)

def main():
    data = [list(map(int, input().split())) for i in range(3)]
    a = ((data[0][0] - data[1][0]) ** 2 + (data[0][1] - data[1][1]) ** 2) ** 0.5
    b = ((data[1][0] - data[2][0]) ** 2 + (data[1][1] - data[2][1]) ** 2) ** 0.5
    c = ((data[0][0] - data[2][0]) ** 2 + (data[0][1] - data[2][1]) ** 2) ** 0.5

    s = (a + b + c) / 2
    S = (s * (s - a) * (s - b) * (s - c)) ** 0.5
    r = 2 * S / (a + b + c)

    left, right = 0, max(a, b, c)

    check(max(a, b, c), left, right, r, 0)





if __name__ == '__main__':
    main()
    # test()

Submission status: Time Limit Exceeded

Solution code:
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**15
mod = 10**9+7

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 bs(f, mi, ma):
    mm = -1
    while ma > mi + eps:
        mm = (ma+mi) / 2.0
        if f(mm):
            mi = mm + eps
        else:
            ma = mm
    if f(mm):
        return mm + eps
    return mm

def main():
    xy = sorted([LI() for _ in range(3)])
    x = list(map(lambda _: _[0] - xy[0][0], xy))
    y = list(map(lambda _: _[1] - xy[0][1], xy))
    a = []
    for i in range(3):
        a.append(((x[i] - x[i-1])**2 + (y[i] - y[i-1])**2) ** 0.5)
    ma = max(a)
    s = abs(x[1]*y[2] - x[2]*y[1]) / 2
    r = 2 * s / sum(a)

    def f(i):
        return (1-i/r) * ma - 2*i > 0


    return bs(f, 0, ma)




print(main())

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque

def check(max_length, left, right, r, index):
    if index == 1000:
        print(left)
        sys.exit()
    half = (left + right) / 2
    if 2 * half <= max_length * (r - half) / r:
        check(max_length, half, right, r, index + 1)
    else:
        check(max_length, left, half, r, index + 1)

def main():
    data = [list(map(int, input().split())) for i in range(3)]
    a = ((data[0][0] - data[1][0]) ** 2 + (data[0][1] - data[1][1]) ** 2) ** 0.5
    b = ((data[1][0] - data[2][0]) ** 2 + (data[1][1] - data[2][1]) ** 2) ** 0.5
    c = ((data[0][0] - data[2][0]) ** 2 + (data[0][1] - data[2][1]) ** 2) ** 0.5

    s = (a + b + c) / 2
    S = (s * (s - a) * (s - b) * (s - c)) ** 0.5
    r = 2 * S / (a + b + c)

    left, right = 0, max(a, b, c)

    check(max(a, b, c), left, right, r, 0)





if __name__ == '__main__':
    main()
    # test()

Submission status: Accepted

Solution code:
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**10
mod = 10**9+7

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 bs(f, mi, ma):
    mm = -1
    while ma > mi + eps:
        mm = (ma+mi) / 2.0
        if f(mm):
            mi = mm + eps
        else:
            ma = mm
    if f(mm):
        return mm + eps
    return mm

# 面積
def area(xy):
    xy = sorted(xy)
    x = [xy[i][0] - xy[0][0] for i in range(3)]
    y = [xy[i][1] - xy[0][1] for i in range(3)]
    return abs(x[1]*y[2] - x[2]*y[1]) / 2

# 内接円の半径
def inside_r(xy):
    s = area(xy)
    a = [((xy[i][0] - xy[i-1][0])**2 + (xy[i][1] - xy[i-1][1])**2) ** 0.5 for i in range(3)]
    return 2 * s / sum(a)

def main():
    xy = sorted([LI() for _ in range(3)])
    a = [((xy[i][0] - xy[i-1][0])**2 + (xy[i][1] - xy[i-1][1])**2) ** 0.5 for i in range(3)]
    ma = max(a)
    r = inside_r(xy)

    def f(i):
        return (1-i/r) * ma - 2*i > 0


    return bs(f, 0, ma)




print(main())

Submission status: Accepted

Solution code:
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**10
mod = 10**9+7

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 bs(f, mi, ma):
    mm = -1
    while ma > mi + eps:
        mm = (ma+mi) / 2.0
        if f(mm):
            mi = mm + eps
        else:
            ma = mm
    if f(mm):
        return mm + eps
    return mm

def main():
    xy = sorted([LI() for _ in range(3)])
    x = list(map(lambda _: _[0] - xy[0][0], xy))
    y = list(map(lambda _: _[1] - xy[0][1], xy))
    a = []
    for i in range(3):
        a.append(((x[i] - x[i-1])**2 + (y[i] - y[i-1])**2) ** 0.5)
    ma = max(a)
    s = abs(x[1]*y[2] - x[2]*y[1]) / 2
    r = 2 * s / sum(a)

    def f(i):
        return (1-i/r) * ma - 2*i > 0


    return bs(f, 0, ma)




print(main())