Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Circumscribed Circle of A Triangle.

Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface. 

Input

Input consists of several datasets. In the first line, the number of datasets $n$ is given. Each dataset consists of:

$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$

in a line. All the input are real numbers.

Output

For each dataset, print $p_x$, $p_y$ and $r$ separated by a space in a line. Print the solution to three places of decimals. Round off the solution to three decimal places.

Constraints

$-100 \leq x_1, y_1, x_2, y_2, x_3, y_3 \leq 100$

$ n \leq 20$

Sample Input

1
0.0 0.0 2.0 0.0 2.0 2.0

Output for the Sample Input

1.000 1.000 1.414



Sample input:
1
0.0 0.0 2.0 0.0 2.0 2.0


Sample output:
1.000 1.000 1.414

Submission status: Accepted

Solution code:
# Aizu Problem 0010: Circumscribed Circle of a Triangle
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def circumscribed_circle(x1, y1, x2, y2, x3, y3):
    d = 2 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))
    px = ( (x1**2 + y1**2) * (y2 - y3) + (x2**2 + y2**2) * (y3 - y1) + (x3**2 + y3**2) * (y1 - y2) ) / d
    py = ( (x1**2 + y1**2) * (x3 - x2) + (x2**2 + y2**2) * (x1 - x3) + (x3**2 + y3**2) * (x2 - x1) ) / d
    a = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
    b = math.sqrt((x1 - x3)**2 + (y1 - y3)**2)
    c = math.sqrt((x2 - x3)**2 + (y2 - y3)**2)
    s = (a + b + c) / 2
    A = math.sqrt(s * (s - a) * (s - b) * (s - c))
    r = a * b * c / (4 * A)
    return px, py, r

          
N = int(input())
for k in range(N):
    x1, y1, x2, y2, x3, y3 = [float(_) for _ in input().split()]
    px, py, r = circumscribed_circle(x1, y1, x2, y2, x3, y3)
    print("%.3f %.3f %.3f" % (px, py, r))

Submission status: Accepted

Solution code:
import math
a=int(input())
for i in range(a):
    x1,y1,x2,y2,x3,y3=[float(j) for j in input().split()]
    A=x1**2+y1**2-x2**2-y2**2
    B=x2**2+y2**2-x3**2-y3**2
    x12=x1-x2
    x23=x2-x3
    y12=y1-y2
    y23=y2-y3
    x=(y23*A-y12*B)/(2*(x12*y23-x23*y12))
    if (y12==0):
        y=(B-2*x23*x)/(2*y23)
    else:
        y=(A-2*x12*x)/(2*y12)
    r=math.sqrt((x1-x)**2+(y1-y)**2)
    print('{:.3f} {:.3f} {:.3f}'.format(x,y,r))

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    a,d,b,e,c,f=map(float,input().split())
    z=2*(b*f-c*e+c*d-a*f+a*e-b*d)
    x=((e-f)*(a**2+d**2)+(f-d)*(b**2+e**2)+(d-e)*(c**2+f**2))/z
    y=((c-b)*(a**2+d**2)+(a-c)*(b**2+e**2)+(b-a)*(c**2+f**2))/z
    print('{0:.3f} {1:.3f} {2:.3f}'.format(x,y,((a-x)**2+(d-y)**2)**0.5))

Submission status: Accepted

Solution code:
def pp(x):
    if x==0:
        x=0
    return "{0:.3f}".format(round(x,3))


n=int(input())
for i in range(n):
    x1,y1,x2,y2,x3,y3=map(float, input().split())

    a=2*(x2-x1)
    b=2*(y2-y1)
    c=( x2**2 + y2**2 ) - ( x1**2 + y1**2 )
    d=2*(x3-x1)
    e=2*(y3-y1)
    f=( x3**2 + y3**2 ) - ( x1**2 + y1**2 )
    x=(c*e-b*f)/(a*e-b*d)
    y=(a*f-c*d)/(a*e-b*d)
    r=( (x-x1)**2 + (y-y1)**2 )**0.5
 
    print(pp(x), pp(y), pp(r))

Submission status: Accepted

Solution code:
def line(grad, x, y):
	return [grad, y - grad * x]
 
def intersection(a, b, c, d):
	return [-(b-d)/(a-c), -(b-d)/(a-c)*a+b]
 
n = input()
for i in range(n):
	x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
	a, b = line(-1 / ((y1 - y2) / (x1 - x2 + 0.000000001) + 0.000000001), (x1 + x2) / 2, (y1 + y2) / 2)
	c, d = line(-1 / ((y3 - y2) / (x3 - x2 + 0.000000001) + 0.000000001), (x3 + x2) / 2, (y3 + y2) / 2)
	px, py = intersection(a, b, c, d)
	print "%.3f %.3f %.3f" % (px, py, ((px - x1)**2 + (py - y1)**2)**0.5)

Submission status: Accepted

Solution code:
# coding=utf-8
import math


if __name__ == '__main__':
    n = int(input())
    for i in range(n):
        x1, y1, x2, y2, x3, y3 = map(float, input().split())
        points_list = [[x1, y1], [x2, y2], [x3, y3]]
        points_list.sort()

        if points_list[0][0] == points_list[1][0]:
            py = (points_list[0][1] + points_list[1][1])/2
            if points_list[2][1] == points_list[0][1]:
                px = (points_list[0][0] + points_list[2][0])/2
            else:
                a2_s = (points_list[2][1] - points_list[0][1])/(points_list[2][0] - points_list[0][0])
                a2 = -1/a2_s
                m13x = (points_list[0][0] + points_list[2][0])/2
                m13y = (points_list[0][1] + points_list[2][1])/2
                b2 = m13y - a2*m13x
                px = (py - b2)/a2
        elif points_list[1][0] == points_list[2][0]:
            py = (points_list[1][1] + points_list[2][1])/2
            if points_list[2][1] == points_list[0][1]:
                px = (points_list[0][0]+points_list[2][0])/2
            else:
                a2_s = (points_list[2][1] - points_list[0][1])/(points_list[2][0] - points_list[0][0])
                a2 = -1/a2_s
                m13x = (points_list[0][0] + points_list[2][0])/2
                m13y = (points_list[0][1] + points_list[2][1])/2
                b2 = m13y - a2*m13x
                px = (py - b2)/a2
        elif points_list[0][1] == points_list[1][1]:
            px = (points_list[0][0] + points_list[1][0])/2
            a2_s = (points_list[2][1] - points_list[0][1]) / (points_list[2][0] - points_list[0][0])
            a2 = -1 / a2_s
            m13x = (points_list[0][0] + points_list[2][0]) / 2
            m13y = (points_list[0][1] + points_list[2][1]) / 2
            b2 = m13y - a2 * m13x
            py = a2*px + b2
        elif points_list[0][1] == points_list[2][1]:
            px = (points_list[0][0] + points_list[2][0])/2
            a1_s = (points_list[1][1] - points_list[0][1]) / (points_list[1][0] - points_list[0][0])
            a1 = -1 / a1_s
            m12x = (points_list[0][0] + points_list[1][0]) / 2
            m12y = (points_list[0][1] + points_list[1][1]) / 2
            b1 = m12y - a1 * m12x
            py = a1 * px + b1
        else:
            a1_s = (points_list[1][1] - points_list[0][1])/(points_list[1][0] - points_list[0][0])
            a1 = -1/a1_s
            a2_s = (points_list[2][1] - points_list[0][1])/(points_list[2][0] - points_list[0][0])
            a2 = -1/a2_s
            m12x = (points_list[0][0] + points_list[1][0]) / 2
            m12y = (points_list[0][1] + points_list[1][1]) / 2
            m13x = (points_list[0][0] + points_list[2][0]) / 2
            m13y = (points_list[0][1] + points_list[2][1]) / 2
            b1 = m12y - a1 * m12x
            b2 = m13y - a2 * m13x
            px = (b2 - b1)/(a1 - a2)
            py = a1*px + b1
        r = math.sqrt(math.pow((px-points_list[0][0]), 2) + math.pow((py-points_list[0][1]), 2))
        print('{0:.3f} {1:.3f} {2:.3f}'.format(px, py, r))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    px = ((y1-y3) * (y1**2-y2**2+x1**2-x2**2) -
          (y1-y2) * (y1**2-y3**2+x1**2-x3**2)) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3))
    py = ((x1-x3) * (x1**2-x2**2+y1**2-y2**2) -
          (x1-x2) * (x1**2-x3**2+y1**2-y3**2)) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3))
    r = ((x1 - px)**2 + (y1 - py)**2)**0.5
    print('{0:.3f} {1:.3f} {2:.3f}'.format(px, py, r))

Submission status: Accepted

Solution code:
import math

n = int(input())
for i in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())

    s = 0.5*((x1-x3)*(y2-y3) - (x2-x3)*(y1-y3))
    a = (x2-x3)**2 + (y2-y3)**2
    b = (x1-x3)**2 + (y1-y3)**2
    c = (x2-x1)**2 + (y2-y1)**2

    rx = (a*(b+c-a)*x1 + b*(c+a-b)*x2 + c*(a+b-c)*x3)/(16*s**2)
    ry = (a*(b+c-a)*y1 + b*(c+a-b)*y2 + c*(a+b-c)*y3)/(16*s**2)
    r = math.sqrt((rx-x1)**2 + (ry-y1)**2)
    print( "{0:.3f} {1:.3f} {2:.3f}".format(rx+0, ry+0, r+0))

Submission status: Accepted

Solution code:
n = int(raw_input())
i = 0
while (i < n):
    x1,y1,x2,y2,x3,y3=map(float,raw_input().split())
    m1,m2=(x1+x2) / 2, (y1+y2) / 2
    n1,n2=(x1+x3) / 2, (y1+y3) / 2

    if y1==y2:
        a = 1
        b = 0
        c = m1
    elif x1==x2:
        a = 0
        b = 1
        c = m2
    else:
        a = (x2-x1) / (y2-y1)
        b = 1
        c = m2+a*m1

    if y1==y3:
        d = 1
        e = 0
        f = n1
    elif x1==x3:
        d = 0
        e = 1
        f = n2
    else:
        d = (x3-x1) / (y3-y1)
        e = 1
        f = n2+d*n1

    if a*d-b*c==0:
        print "not exist answer"
    else:
        x = (float((c*e-b*f)) / (a*e-b*d))+0
        y = (float((a*f-c*d)) / (a*e-b*d))+0
        print ('%.3f' % round(x,3)), ('%.3f' % round(y,3)), ('%.3f' % round(((((x - x1)**2+(y-y1)**2)**0.5)),3))
    i += 1

Submission status: Accepted

Solution code:
import math
N = int(input())
for i in range(N):
	x1,y1,x2,y2,x3,y3 = map(float,input().split())
	
	x =((y1-y3)*(y1*y1 -y2*y2 +x1*x1 -x2*x2) -(y1-y2)*(y1*y1 -y3*y3 +x1*x1 -x3*x3)) / (2*((y1-y3)*(x1-x2)-(y1-y2)*(x1-x3)))
	y =((x1-x3)*(x1*x1 -x2*x2 +y1*y1 -y2*y2) -(x1-x2)*(x1*x1 -x3*x3 +y1*y1 -y3*y3)) / (2*((x1-x3)*(y1-y2)-(x1-x2)*(y1-y3)))
	r = (x-x1)*(x-x1)+(y-y1)*(y-y1)
	print("{0:.3f} {1:.3f} {2:.3f}".format(x,y,math.sqrt(r)))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    a = pow((x3-x2) ** 2 + (y3-y2) ** 2, 0.5)
    b = pow((x3-x1) ** 2 + (y3-y1) ** 2, 0.5)
    c = pow((x1-x2) ** 2 + (y1-y2) ** 2, 0.5)
    cosA = (b**2 + c**2 - a**2) / (2*b*c)
    sinA = pow(1 - cosA**2, 0.5)
    R = a / sinA / 2
    a, b, c = x1-x2, y1-y2, -(x1**2 + y1**2) + (x2**2 + y2**2)
    d, e, f = x2-x3, y2-y3, -(x2**2 + y2**2) + (x3**2 + y3**2)
    l = (c*e - b*f) / (e*a - b*d)
    m = (c*d - a*f) / (b*d - a*e)
    l, m = l*-0.5, m*-0.5
    print("{:.3f} {:.3f} {:.3f}".format(l, m, R))

Submission status: Accepted

Solution code:
import math

N = int(input())

for l in range(N):
    x1,y1,x2,y2,x3,y3 = [float(i) for i in input().split()]

    # ax + by = e
    # cx + dy = f

    a,b,c = x1-x2, y1-y2, (x1-x2)*(x1+x2)/2 + (y1-y2)*(y1+y2)/2
    d,e,f = x1-x3, y1-y3, (x1-x3)*(x1+x3)/2 + (y1-y3)*(y1+y3)/2

    X = (c*e-f*b)/(a*e-b*d)
    Y = (f*a-c*d)/(a*e-b*d)
    R = math.sqrt((X-x1)*(X-x1)+(Y-y1)*(Y-y1))

    print(format(X, '.3f'), format(Y, '.3f'), format(R, '.3f'))

Submission status: Accepted

Solution code:
for _ in[0]*int(input()):
 a,b,c,d,e,f=map(float,input().split())
 x=((a*a+b*b)*(d-f)+(c*c+d*d)*(f-b)+(e*e+f*f)*(b-d))/2/(a*(d-f)+c*(f-b)+e*(b-d))
 y=((a*a+b*b)*(c-e)+(c*c+d*d)*(e-a)+(e*e+f*f)*(a-c))/2/(b*(c-e)+d*(e-a)+f*(a-c))
 print(f"{x:.3f} {y:.3f} {((x-a)**2+(y-b)**2)**.5:.3f}")

Submission status: Accepted

Solution code:
for _ in[0]*int(input()):
 a,b,c,d,e,f=map(float,input().split())
 x=((a*a+b*b)*(d-f)+(c*c+d*d)*(f-b)+(e*e+f*f)*(b-d))/2/(a*(d-f)+c*(f-b)+e*(b-d))
 y=((a*a+b*b)*(c-e)+(c*c+d*d)*(e-a)+(e*e+f*f)*(a-c))/2/(b*(c-e)+d*(e-a)+f*(a-c))
 print('%.3f %.3f %.3f'%(x,y,((x-a)**2+(y-b)**2)**.5))

Submission status: Accepted

Solution code:
for _ in[0]*int(input()):
 a,b,c,d,e,f=map(float,input().split())
 s,t,u=a*a+b*b,c*c+d*d,e*e+f*f
 x=(s*(d-f)+t*(f-b)+u*(b-d))/2/(a*(d-f)+c*(f-b)+e*(b-d))
 y=(s*(c-e)+t*(e-a)+u*(a-c))/2/(b*(c-e)+d*(e-a)+f*(a-c))
 print('%.3f %.3f %.3f'%(x,y,((x-a)**2+(y-b)**2)**.5))

Submission status: Accepted

Solution code:
import math
for _ in[0]*int(input()):
 a,b,c,d,e,f=map(float,input().split())
 s,t,u=a*a+b*b,c*c+d*d,e*e+f*f
 x=(s*(d-f)+t*(f-b)+u*(b-d))/2/(a*(d-f)+c*(f-b)+e*(b-d))
 y=(s*(c-e)+t*(e-a)+u*(a-c))/2/(b*(c-e)+d*(e-a)+f*(a-c))
 print('%.3f %.3f %.3f'%(x,y,math.hypot(x-a,y-b)))

Submission status: Accepted

Solution code:
from math import sqrt
n=input()
for i in range(n):
    x1,y1,x2,y2,x3,y3=map(float,raw_input().split())
    A1=2*(x2-x1)
    B1=2*(y2-y1)
    C1=x2**2+y2**2-x1**2-y1**2
    A2=2*(x3-x2)
    B2=2*(y3-y2)
    C2=x3**2+y3**2-x2**2-y2**2
    x=(C1*B2-C2*B1)/(A1*B2-A2*B1)
    y=(A1*C2-A2*C1)/(A1*B2-A2*B1)
    R=sqrt((x1-x)**2+(y1-y)**2)
    print"%.3f %.3f %.3f"%(x,y,R)

Submission status: Accepted

Solution code:
import math
n=int(input())
for i in range(n):
    x1,y1,x2,y2,x3,y3=[float(i) for i in input().split()]
    A=math.hypot(x2-x3,y2-y3)**2
    B=math.hypot(x1-x3,y1-y3)**2
    C=math.hypot(x1-x2,y1-y2)**2
    t1=A*(B+C-A)
    t2=B*(A+C-B)
    t3=C*(A+B-C)
    px=(t1*x1+t2*x2+t3*x3)/(t1+t2+t3)
    py=(t1*y1+t2*y2+t3*y3)/(t1+t2+t3)
    r=math.hypot(px-x1,py-y1)
    print("%.3f %.3f %.3f"%(round(px,3),round(py,3),round(r,3)))

Submission status: Accepted

Solution code:
for _ in[0]*int(input()):
 a,b,c,d,e,f=map(float,input().split())
 s,t,u=a*a+b*b,c*c+d*d,e*e+f*f
 x=(s*(d-f)+t*(f-b)+u*(b-d))/2/(a*(d-f)+c*(f-b)+e*(b-d))
 y=(s*(c-e)+t*(e-a)+u*(a-c))/2/(b*(c-e)+d*(e-a)+f*(a-c))
 print(f'{x:.3f} {y:.3f} {((x-a)**2+(y-b)**2)**.5:.3f}')

Submission status: Accepted

Solution code:
import math
for _ in range(int(input())):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    p = ((y1-y3)*(y1**2 -y2**2 +x1**2 -x2**2) -(y1-y2)*(y1**2 -y3**2 +x1**2 -x3**2)) / 2/ ((y1-y3)*(x1-x2)-(y1-y2)*(x1-x3))
    q = ((x1-x3)*(x1**2 -x2**2 +y1**2 -y2**2) -(x1-x2)*(x1**2 -x3**2 +y1**2 -y3**2)) / 2/ ((x1-x3)*(y1-y2)-(x1-x2)*(y1-y3))
    r = math.sqrt((x1 - p) ** 2 + (y1 - q) ** 2)
    p = abs(p) if abs(p) < 10e-5 else p
    q = abs(q) if abs(q) < 10e-5 else q
    print("{:.3f} {:.3f} {:.3f}".format(p, q, r))

Submission status: Accepted

Solution code:
import math
for _ in range(int(input())):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    p = ((y1-y3)*(y1**2 -y2**2 +x1**2 -x2**2) -(y1-y2)*(y1**2 -y3**2 +x1**2 -x3**2)) / 2/ ((y1-y3)*(x1-x2)-(y1-y2)*(x1-x3))
    q = ((x1-x3)*(x1**2 -x2**2 +y1**2 -y2**2) -(x1-x2)*(x1**2 -x3**2 +y1**2 -y3**2)) / 2/ ((x1-x3)*(y1-y2)-(x1-x2)*(y1-y3))
    r = math.sqrt((x1 - p) ** 2 + (y1 - q) ** 2)
    print("{:.3f} {:.3f} {:.3f}".format(p, q, r))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from math import sqrt
# import numpy as np


n = int(input())

for i in range(n):
    tmp = input().split(' ')
    
    a, b, c = [(float(tmp[i]), float(tmp[i+1])) for i in range(0, len(tmp), 2)]
    
    #A = np.array(((a[0], a[1], 1),
    #              (b[0], b[1], 1),
    #              (c[0], c[1], 1)))
    A_tmp1 = 1/(a[0]*b[1] + a[1]*c[0] + b[0]*c[1] - b[1]*c[0] - a[1]*b[0] - a[0]*c[1])
    A_tmp2 = [[b[1]-c[1], -(a[1]-c[1]), a[1]-b[1]],
              [-(b[0]-c[0]),  (a[0]-c[0]), -(a[0]-b[0])],
              [b[0]*c[1] - b[1]*c[0], -(a[0]*c[1] - a[1]*c[0]), a[0]*b[1] - a[1]*b[0]]]
    A = [list(map(lambda x: A_tmp1*x, A_tmp2[i])) for i in range(3)]
    
    #B = np.array((((-(a[0]**2 + a[1]**2))),
    #              ((-(b[0]**2 + b[1]**2))),
    #              ((-(c[0]**2 + c[1]**2)))))
    B = [[-(a[0]**2 + a[1]**2)],
         [-(b[0]**2 + b[1]**2)],
         [-(c[0]**2 + c[1]**2)]]
    
    
    tmp = [sum([A[i][j]*B[j][0] for j in range(3)]) for i in range(3)]
    # tmp = np.dot(np.linalg.inv(A), B)
    
    x = -tmp[0]/2
    y = -tmp[1]/2
    r = sqrt((tmp[0]**2 + tmp[1]**2 - 4*tmp[2])/4)
    
    print('{:.3f} {:.3f} {:.3f}'.format(x, y, r))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from math import *
def g(x):
	y = (int((1000 * abs(x)) * 2 + 1) // 2) / 1000
	if x < 0:
		y *= -1
	return y
def func(x):
	x1, y1, x2, y2, x3, y3 = x
	
	a = x1 - x2
	b = y1 - y2
	c = (x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2) / 2
	d = x1 - x3
	e = y1 - y3
	f = (x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3) / 2
	x = (e * c - b * f) / (a * e - b * d)
	y = (a * f - d * c) / (a * e - b * d)
	r = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y))
	x = "{0:.3f}".format(g(x))
	y = "{0:.3f}".format(g(y))
	r = "{0:.3f}".format(g(r))
	print(x + " " + y + " " + r)
n = int(input())
a = []
for _ in range(n):
	a.append(list((map(float, input().split()))))
for i in a:
	func(i)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from math import *
def g(x):
	y = (int((1000 * abs(x)) * 2 + 1) // 2) / 1000
	if x < 0:
		y *= -1
	return y
def func(x):
	x1, y1, x2, y2, x3, y3 = x

	vx1 = x2 - x1
	vy1 = y2 - y1
	vx2 = x3 - x1
	vy2 = y3 - y1
	k = (vx2 ** 2 + vy2 ** 2 - vx1 * vx2 - vy1 * vy2) / (vy1 * vx2 - vx1 * vy2) / 2
	x = vx1 / 2 + k * vy1 + x1
	y = vy1 / 2 - k * vx1 + y1
	r = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y))
	x = "{0:.3f}".format(g(x))
	y = "{0:.3f}".format(g(y))
	r = "{0:.3f}".format(g(r))
	print(x + " " + y + " " + r)
n = int(input())
a = []
for _ in range(n):
	a.append(list((map(float, input().split()))))
for i in a:
	func(i)

Submission status: Accepted

Solution code:
from math import *
def g(x):
    y = (int((1000 * abs(x)) * 2 + 1) // 2) / 1000
    if x < 0:
        y *= -1
    return y
'''
def f(x):
    a = (x[2] - x[4]) * (x[1] - x[3]) - (x[0] - x[2]) * (x[3] - x[5])
    b = (x[0] - x[2]) * (x[4] - x[0]) - (x[5] - x[1]) * (x[1] - x[3])
    l = 0.5 * b / a
    X = 0.5 * x[2] + 0.5 * x[4] + l * (x[3] - x[5])
    Y = 0.5 * x[3] + 0.5 * x[5] + l * (x[4] - x[2])
    R = sqrt((X - x[0]) ** 2 + (Y - x[1]) ** 2)
    X = g(X)
    Y = g(Y)
    R = g(R)
    print("{0:.3f} {1:.3f} {2:.3f}".format(X, Y, R))
'''
def f(x):
    x1, y1, x2, y2, x3, y3 = x
    X1 = x1 - x3
    Y1 = y1 - y3
    X2 = x2 - x3
    Y2 = y2 - y3
    k  = (X2 ** 2 + Y2 ** 2 -X1 * X2 - Y1 * Y2) / (2 * (X2 * Y1 - X1 * Y2))
    X  = X1 / 2 + k * Y1 + x3
    Y  = Y1 / 2 - k * X1 + y3
    R = sqrt((X - x1) ** 2 + (Y - y1) ** 2)
    X = g(X)
    Y = g(Y)
    R = g(R)
    print("{0:.3f} {1:.3f} {2:.3f}".format(X, Y, R))

n = int(input())
a = []
for _ in range(n):
    a.append(list((map(float, input().split()))))
for i in a:
    f(i)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from math import *
def g(x):
	y = (int((1000 * abs(x)) * 2 + 1) // 2) / 1000
	if x < 0:
		y *= -1
	return y
def func(x):
	x1, y1, x2, y2, x3, y3 = x

	vx1 = x2 - x1
	vy1 = y2 - y1
	vx2 = x3 - x1
	vy2 = y3 - y1
	k = (vx2 ** 2 + vy2 ** 2 - vx1 * vx2 - vy1 * vy2) / (vy1 * vx2 - vx1 * vy2) / 2
	x = vx1 / 2 + k * vy1 + x1
	y = vy1 / 2 - k * vx1 + y1
	r = sqrt((x1 - x) ** 2 + (y1 - y) ** 2)
	print("{0:.3f} {1:.3f} {2:.3f}".format(g(x), g(y), g(r)))
n = int(input())
for _ in range(n):
	func(list(map(float, input().split())))

Submission status: Accepted

Solution code:
from decimal import Decimal
import math
for _ in range(int(input())):
    x1,y1,x2,y2,x3,y3=list(map(Decimal,input().split()))
    a=x1-x3
    b=y2-y3
    c=x2-x3
    d=y1-y3
    e=y1-y2
    f=x1+x3
    g=x2+x3
    X=(b*d*e+a*b*f-c*d*g)/2/(a*b-c*d)
    try:
        Y=-(a/d)*(X-f/2)+(y1+y3)/2
    except:
        Y=-(c/b)*(X-g/2)+(y2+y3)/2
    R=math.sqrt((x1-X)**2+(y1-Y)**2)
    print(" ".join(["{:.3f}".format(i) for i in [X,Y,R]]))

Submission status: Accepted

Solution code:
# AOJ 0010 Circumscribed Circle of a Triangle
# Python3 2018.6.22 bal4u

import math
EPS = 1e-8

def cross(a, b):
	return a.real*b.imag - a.imag*b.real
def dist(a, b):
	return math.hypot(a.real-b.real, a.imag-b.imag)
	
# 両直線の交点
def crossPointLL(ln1, ln2):
	u = ln1[1]-ln1[0]
	v = ln2[1]-ln2[0]
	return ln1[0] + u*(cross(v, ln2[0]-ln1[0])/cross(v, u))

# 入力:３点座標、リターン:外接円の円心座標、半径を表すリスト
def circumscribed_circle(p1, p2, p3):
	p12 = (p1+p2)/2
	p23 = (p2+p3)/2
	ln1 = [p12, p12+(p1-p2)*complex(0, 1)]
	ln2 = [p23, p23+(p2-p3)*complex(0, 1)]
	c = crossPointLL(ln1, ln2)
	return [c, dist(c, p1)]

for i in range(int(input())):
	p = list(map(float, input().split()))
	p1 = complex(p[0], p[1])
	p2 = complex(p[2], p[3])
	p3 = complex(p[4], p[5])
	ans = circumscribed_circle(p1, p2, p3)
	print(format(ans[0].real+EPS, ".3f"), format(ans[0].imag+EPS, ".3f"), format(ans[1]+EPS, ".3f"))

Submission status: Accepted

Solution code:

import math

PI = math.pi
EPS = 10**-10

def edge(a, b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**.5

def area(a, b, c):
    s = (a+b+c)/2
    return (s*(s-a)*(s-b)*(s-c))**.5

def LawOfCosines(a, b, c): #余弦定理
    return math.acos( (b*b+c*c-a*a) / (2.0*b*c) );

def is_same(x, y): 
    return abs(x-y) < EPS

class Triangle:
    def __init__(self, p):
        a, b, c = p
        self.a = a
        self.b = b
        self.c = c

        self.edgeA = edge(b, c)
        self.edgeB = edge(c, a)
        self.edgeC = edge(a, b)

        self.area = area(self.edgeA, self.edgeB, self.edgeC)

        self.angleA = LawOfCosines(self.edgeA, self.edgeB, self.edgeC)
        self.angleB = LawOfCosines(self.edgeB, self.edgeC, self.edgeA)
        self.angleC = LawOfCosines(self.edgeC, self.edgeA, self.edgeB)

    def circumscribeadCircleRadius(self): #外接円の半径を返す
        return self.edgeA / math.sin(self.angleA) / 2.0

    def circumscribedCircleCenter(self): #外接円の中心の座標を返す
        a = math.sin(2.0*self.angleA);
        b = math.sin(2.0*self.angleB);
        c = math.sin(2.0*self.angleC);
        X = (self.a[0] * a + self.b[0] * b + self.c[0] * c) / (a+b+c);
        Y = (self.a[1] * a + self.b[1] * b + self.c[1] * c) / (a+b+c);
        return X, Y

    def inscribedCircleRadius(self): #内接円の半径
        return 2 * self.area / (self.edgeA + self.edgeB + self.edgeC)

    def inscribedCircleCenter(self): #内接円の中心の座標
        points = [self.a, self.b, self.c]
        edges = [self.edgeA, self.edgeB, self.edgeC]
        s = sum(edges)
        return [sum([points[j][i]*edges[j] for j in range(3)])/s for i in range(2)]

    def isInner(self, p): #点が三角形の内側か判定
        cross = lambda a, b: a[0]*b[1]-a[1]*b[0]

        c1 = 0
        c2 = 0
        points = [self.a, self.b, self.c]
        for i in range(3):
            a = [points[i][0]-points[(i+1)%3][0], points[i][1]-points[(i+1)%3][1]]
            b = [points[i][0]-p[0],  points[i][1]-p[1]]
            c = cross(a, b)
            if c > 0:
                c1 += 1
            elif c < 0:
                c2 += 1
        if c1 == 3 or c2 == 3:
            return True
        else:
            return c1+c2 != 3 and (c1 == 0 or c2 == 0)


if __name__ == "__main__":
    n = int(input())
    for _ in range(n):
        points = []
        c = list(map(float, input().split()))
        points = [(c[i], c[i+1]) for i in range(0, 6, 2)]
        t = Triangle(points)

        #外接円
        x, y = t.circumscribedCircleCenter()
        r = t.circumscribeadCircleRadius()
        print("{:.3f} {:.3f} {:.3f}".format(x,y,r))

Submission status: Accepted

Solution code:
import math

def calc(x, y):
    s = math.fabs((x[1]-x[0])*(y[2]-y[0]) - (x[2]-x[0])*(y[1]-y[0]))/2
    a = ((x[2]-x[1])**2 + (y[2]-y[1])**2)**0.5
    b = ((x[0]-x[2])**2 + (y[0]-y[2])**2)**0.5
    c = ((x[1]-x[0])**2 + (y[1]-y[0])**2)**0.5
    r = a*b*c/(4*s)

    a = [2*(x[1]-x[0]), 2*(x[2]-x[0])]
    b = [2*(y[1]-y[0]), 2*(y[2]-y[0])]
    c = [x[0]**2 - x[1]**2 + y[0]**2 -y[1]**2, x[0]**2 - x[2]**2 + y[0]**2 -y[2]**2]
    x = (b[0]*c[1]-b[1]*c[0])/(a[0]*b[1]-a[1]*b[0])
    y = (c[0]*a[1]-c[1]*a[0])/(a[0]*b[1]-a[1]*b[0])

    return [x,y,r]

for i in range(int(input())):
    list = [float(l) for l in raw_input().split()]
    x,y = [list[0::2],list[1::2]]

    ans = calc(x,y)

    print "%.3f %.3f %.3f" % (ans[0],ans[1],ans[2])

Submission status: Accepted

Solution code:
import sys

n=input()
for line in sys.stdin:
    x=map(float,line.split())[0::2];
    y=map(float,line.split())[1::2];
    #guilty...
    A=x[0]-x[1]
    B=y[0]-y[1]
    C=x[1]-x[2]
    D=y[1]-y[2]
    E=-(x[0]**2+y[0]**2)+(x[1]**2+y[1]**2)
    F=-(x[1]**2+y[1]**2)+(x[2]**2+y[2]**2)
    l=(D*E-B*F)/(A*D-B*C)
    m=(-C*E+A*F)/(A*D-B*C)
    n=-(x[0]**2+y[0]**2+l*x[0]+m*y[0])

    print "{:.3f} {:.3f} {:.3f}".format(-l/2,-m/2,(l**2+m**2-4*n)**0.5/2)

Submission status: Accepted

Solution code:
#coding: utf-8
def solve(a, b, c, d, e, f):
    agn = a*e - b*d
    x = (e*c - b*f)/float(agn)
    y = (-d*c + a*f)/float(agn)
    if x == 0.: x = 0.
    if y == 0.: y = 0.
    return (x, y)
   
while 1:
    try:
        n = input()
        for i in xrange(n):
            x = [0 for i in xrange(3)]
            y = [0 for i in xrange(3)]
            a,b,t = [[0 for i in xrange(2)] for i in xrange(3)]
            p,q,s = [[0 for i in xrange(2)] for i in xrange(3)]
            x[0],y[0],x[1],y[1],x[2],y[2] = map(float, raw_input().split())
            for j in xrange(2):
                a[j] = (x[j+1] + x[j])/2
                b[j] = (y[j+1] + y[j])/2
                if x[j+1] - x[j] == 0.:
                    p[j] = 0.
                    q[j] = -1.
                    s[j] = -b[j]
                elif y[j+1] - y[j] == 0.:
                    p[j] = -1.
                    q[j] = 0.
                    s[j] = -a[j]
                else:
                    t[j] = (y[j+1] - y[j]) / (x[j+1] - x[j])
                    p[j] = -1./t[j]
                    q[j] = -1.
                    s[j] = -(a[j]/t[j])-b[j]
            c = solve(p[0], q[0], s[0], p[1], q[1], s[1])
            r = ((x[0]-c[0])**2 + (y[0]-c[1])**2)**0.5
            print "%.3f %.3f %.3f" % (c[0], c[1], r)
    except EOFError:
        break

Submission status: Accepted

Solution code:
def heron(a,b,c):
    s = 0.5*(a+b+c)
    return (s*(s-a)*(s-b)*(s-c))**0.5

def gaishin(a,b,c,z1,z2,z3,s):
    p = (a**2*(b**2 + c**2 - a**2)*z1 + \
         b**2*(c**2 + a**2 - b**2)*z2 + \
         c**2*(a**2 + b**2 - c**2)*z3)/(16*s**2)
    return p

n = input()

for i in range(n):
    x1,y1,x2,y2,x3,y3 = map(float, raw_input().split(' '))
    l1 = ((x2-x3)**2+(y2-y3)**2)**0.5
    l2 = ((x3-x1)**2+(y3-y1)**2)**0.5
    l3 = ((x1-x2)**2+(y1-y2)**2)**0.5
    s = heron(l1,l2,l3)
    px = gaishin(l1,l2,l3,x1,x2,x3,s)
    py = gaishin(l1,l2,l3,y1,y2,y3,s)
    r = ((px-x1)**2+(py-y1)**2)**0.5
    print '%.3f %.3f %.3f' % (px,py,r)

Submission status: Accepted

Solution code:
import math
from math import *
for i in range(int(raw_input())):
    (x1, y1, x2, y2, x3, y3) = map(float, raw_input().split())
    a1 = 2 * (x2 - x1)
    b1 = 2 * (y2 - y1)
    c1 = x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2
    a2 = 2 * (x3 - x1)
    b2 = 2 * (y3 - y1)
    c2 = x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2
    xp = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1)
    yp = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1)
    r = sqrt((x1 - xp) ** 2 + (y1 - yp) ** 2)
    print '%.3f %.3f %.3f' % (xp, yp, r)

Submission status: Accepted

Solution code:
import math
 
def calc(x, y):
    s = math.fabs((x[1]-x[0])*(y[2]-y[0]) - (x[2]-x[0])*(y[1]-y[0]))/2
    a = ((x[2]-x[1])**2 + (y[2]-y[1])**2)**0.5
    b = ((x[0]-x[2])**2 + (y[0]-y[2])**2)**0.5
    c = ((x[1]-x[0])**2 + (y[1]-y[0])**2)**0.5
    r = a*b*c/(4*s)
 
    a = [2*(x[1]-x[0]), 2*(x[2]-x[0])]
    b = [2*(y[1]-y[0]), 2*(y[2]-y[0])]
    c = [x[0]**2 - x[1]**2 + y[0]**2 -y[1]**2, x[0]**2 - x[2]**2 + y[0]**2 -y[2]**2]
    x = (b[0]*c[1]-b[1]*c[0])/(a[0]*b[1]-a[1]*b[0])
    y = (c[0]*a[1]-c[1]*a[0])/(a[0]*b[1]-a[1]*b[0])
 
    return [x,y,r]
 
for i in range(int(input())):
    list = [float(l) for l in raw_input().split()]
    x,y = [list[0::2],list[1::2]]
 
    ans = calc(x,y)
 
    print "%.3f %.3f %.3f" % (ans[0],ans[1],ans[2])

Submission status: Accepted

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from math import sqrt
N = int(stdin.readline())
for i in xrange(N):
    x1, y1, x2, y2, x3, y3 = (float(n) for n in stdin.readline().split())
    det = x1*y2 + x2*y3 + x3*y1 - x1*y3 - x2*y1 - x3*y2
    a = x1**2 + y1**2
    b = x2**2 + y2**2
    c = x3**2 + y3**2
    L = (a*y2 + b*y3 + c*y1 - a*y3 - b*y1 - c*y2) / det
    M = (x1*b + x2*c + x3*a - x1*c - x2*a - x3*b) / det
    N = (x1*y2*c + x2*y3*a + x3*y1*b - x1*y3*b - x2*y1*c - x3*y2*a) / det
    xp = L / 2.0
    yp = M / 2.0
    r = sqrt(abs(N + xp**2.0 + yp**2.0))
    print('{:.3f} {:.3f} {:.3f}'.format(xp, yp, r))

Submission status: Accepted

Solution code:
from math import sqrt 
ans=[]
n=input()
for i in xrange(n):
    x1,y1,x2,y2,x3,y3=map(float,raw_input().split())
    A1=2*(x2-x1)
    A2=2*(x3-x1)
    B1=2*(y2-y1)
    B2=2*(y3-y1)
    C1=x1**2-x2**2+y1**2-y2**2
    C2=x1**2-x3**2+y1**2-y3**2
    x=(B1*C2-B2*C1)/(A1*B2-A2*B1)
    y=(C1*A2-C2*A1)/(A1*B2-A2*B1)
    r=sqrt((x-x1)**2 + (y-y1)**2)
    ansstr='%.3f %.3f %.3f' % (x,y,r)
    ans.append(ansstr)
for i in ans:
    print i

Submission status: Accepted

Solution code:
import sys
from math import sqrt
n = input()
for line in sys.stdin:
    [x1,y1,x2,y2,x3,y3] = [float(x) for x in line.split()]
    a1 = 2*(x2-x1)
    b1 = 2*(y2-y1)
    c1 = x1**2-x2**2+y1**2-y2**2
    a2 = 2*(x3-x1)
    b2 = 2*(y3-y1)
    c2 = x1**2-x3**2+y1**2-y3**2
    x = (b1*c2-b2*c1)/(a1*b2-a2*b1)
    y = (c1*a2-c2*a1)/(a1*b2-a2*b1)
    a = sqrt((x2-x1)**2 + (y2-y1)**2)
    b = sqrt((x3-x1)**2 + (y3-y1)**2)
    c = sqrt((x3-x2)**2 + (y3-y2)**2)
    r = (a*b*c)/sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c))
    print "%.3f %.3f %.3f" % (x,y,r)

Submission status: Accepted

Solution code:
import math
  
a = int(raw_input())
  
while a > 0:
    a -= 1
    x1,y1,x2,y2,x3,y3 = map(float,raw_input().split())
  
    a1 = 2*(x2-x1)
    b1 = 2*(y2-y1)
    c1 = x1*x1-x2*x2+y1*y1-y2*y2
    a2 = 2*(x3-x1)
    b2 = 2*(y3-y1)
    c2 = x1*x1-x3*x3+y1*y1-y3*y3
  
    X = (b1*c2-b2*c1)/(a1*b2-a2*b1)
    Y = (c1*a2-c2*a1)/(a1*b2-a2*b1)
  
    R = math.sqrt((X-x1)*(X-x1)+(Y-y1)*(Y-y1))                                     
  
    print "%.3f %.3f %.3f" % (X,Y,R)

Submission status: Accepted

Solution code:
import math

a = int(raw_input())

while a	> 0:
    a -= 1
    x1,y1,x2,y2,x3,y3 =	map(float,raw_input().split())

    a1 = 2*(x2-x1)
    b1 = 2*(y2-y1)
    c1 = x1*x1-x2*x2+y1*y1-y2*y2
    a2 = 2*(x3-x1)
    b2 = 2*(y3-y1)
    c2 = x1*x1-x3*x3+y1*y1-y3*y3

    X = (b1*c2-b2*c1)/(a1*b2-a2*b1)
    Y = (c1*a2-c2*a1)/(a1*b2-a2*b1)

    R = math.sqrt((X-x1)*(X-x1)+(Y-y1)*(Y-y1))

    print "%.3f %.3f %.3f" % (X,Y,R)

Submission status: Accepted

Solution code:
import math

def equation(A):
    n = len(A)
    for i in range(n):
        j=i
        while A[j][i]==0:
            j+= 1
        A[i], A[j] = A[j], A[i]
        A[i] = [e / A[i][i] for e in A[i]]
        for j in range(n):
            if j==i: continue
            tmp = A[j][i]
            for k in range(n+1):
                A[j][k] -= tmp * A[i][k]
    return

n=input()
for i in range(n):
    A=[]
    seq = map(float, raw_input().split())
    for j in range(3):
        x = seq.pop(0)
        y = seq.pop(0)
        A.append([x, y, 1, -(x**2+y**2)])
    equation(A)

    x0, y0 = -A[0][3]/2, -A[1][3]/2
    r =((x-x0)**2 + (y-y0)**2)**.5
    print "%.3f %.3f %.3f" %(x0, y0, r)

Submission status: Accepted

Solution code:
import math

n = int(raw_input())

for _ in range(n):
    (x1, y1, x2, y2, x3, y3) = map(float, raw_input().split())

    a1 = (x2 - x1) * 2
    a2 = (x3 - x1) * 2
    b1 = (y2 - y1) * 2
    b2 = (y3 - y1) * 2
    c1 = x1**2 - x2**2 + y1**2 - y2**2
    c2 = x1**2 - x3**2 + y1**2 - y3**2

    x = (b1*c2 - b2*c1) / (a1*b2 - a2*b1)
    y = (c1*a2 - c2*a1) / (a1*b2 - a2*b1)
    r = math.sqrt((x-x1)**2 + (y-y1)**2)

    print '{0:.3f} {1:.3f} {2:.3f}'.format(x, y, r)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import math


n = 0
datas = []

for (i, line) in enumerate(sys.stdin):
	if i == 0:
		n = int(line)
	else:
		datas.append(map(float, line.split()))

for data in datas:
	x1, y1, x2, y2, x3, y3 = data
	a1 = x2 - x1
	b1 = y2 - y1
	a2 = x3 - x1
	b2 = y3 - y1
	px = (b2 * (a1 * a1 + b1 * b1) - b1 * (a2 * a2 + b2 * b2)) / (2 * (a1 * b2 - a2 * b1))
	py = (a1 * (a2 * a2 + b2 * b2) - a2 * (a1 * a1 + b1 * b1)) / (2 * (a1 * b2 - a2 * b1))
	r = math.sqrt(px * px + py * py)
	px += x1
	py += y1
	print "{0:.3f} {1:.3f} {2:.3f}".format(px, py, r)