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:
# -*- coding: utf-8 -*-

import math

class Point_Class():
    def __init__(self, x, y):
        self.x = x
        self.y = y

def calcCenter(p1, p2, p3):
    p = ((p1.y-p2.y)*(p3.x*p3.x+p1.y*p2.y)+(p2.y-p3.y)*(p1.x*p1.x+p2.y*p3.y)+(p3.y-p1.y)*(p2.x*p2.x+p3.y*p1.y)) / ((-2)*(p1.y*(p2.x-p3.x)+p2.y*(p3.x-p1.x)+p3.y*(p1.x-p2.x)))
    q = ((p1.x-p2.x)*(p3.y*p3.y+p1.x*p2.x)+(p2.x-p3.x)*(p1.y*p1.y+p2.x*p3.x)+(p3.x-p1.x)*(p2.y*p2.y+p3.x*p1.x)) / ((-2)*(p1.x*(p2.y-p3.y)+p2.x*(p3.y-p1.y)+p3.x*(p1.y-p2.y)))
    return Point_Class(p, q)

def calcRadius(p, pc):
    return math.sqrt(pow((p.x-pc.x), 2)+pow((p.y-pc.y), 2))

n = int(raw_input())
for i in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
    p1 = Point_Class(x1, y1)
    p2 = Point_Class(x2, y2)
    p3 = Point_Class(x3, y3)
    pc = calcCenter(p1, p2, p3)
    r = calcRadius(p1, pc)
    print "%.3f %.3f %.3f" %(pc.x, pc.y, r)

Submission status: Accepted

Solution code:
def perpendicular_bisector(p, q):
    x = (q[0] - p[0])
    y = (q[1] - p[1])
    return (2 * x, 2 * y, p[0]**2-q[0]**2+p[1]**2-q[1]**2)


def gauss_jordan_elimination(Array):
    # N???M??????Array
    N = len(Array)
    if N == 0:
        return (True, Array)
    else:
        M = len(Array[0])

    A = []
    for i in range(len(Array)):
        A.append(Array[i][:])

    pivot = 0
    L = min(N, M)
    while pivot < L:
        pivot_v = A[pivot][pivot]
        pivot_row = pivot
        for i in range(pivot + 1, L):
            v = max(A[i][pivot], -A[i][pivot])
            if pivot_v < v:
                pivot_row = i
                pivot_v = v
        if pivot_row > pivot:
            for i in range(M):
                A[pivot][i], A[pivot_row][i] = A[pivot_row][i], A[pivot][i]
        if pivot_v == 0:
            return ('False', A)
        inv_pivot = 1 / A[pivot][pivot]
        A[pivot][pivot] = 1
        for i in range(pivot + 1, M):
            A[pivot][i] *= inv_pivot
        for i in range(N):
            if i == pivot:
                continue
            t = -1 * A[i][pivot]
            A[i][pivot] = 0
            for j in range(pivot + 1, M):
                A[i][j] += t * A[pivot][j]
        pivot += 1
    return ('True', A)

n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    a = list(perpendicular_bisector((x1, y1), (x2, y2)))
    b = list(perpendicular_bisector((x1, y1), (x3, y3)))
    c = [a, b]
    state, c = gauss_jordan_elimination(c)
    x = -c[0][2]
    y = -c[1][2]
    r = ((x - x1)**2 + (y - y1)**2)**0.5
    print('{0:.3f} {1:.3f} {2:.3f}'.format(round(x, 3), round(y, 3), round(r, 3)))

Submission status: Accepted

Solution code:
from math import sqrt

def circle(x1, y1, x2, y2, x3, y3):
    if x1 == 0:
        dx = 1
        x1 = x1 + dx
        x2 = x2 + dx
        x3 = x3 + dx
    else:
        dx = 0
    if y2 == 0:
        dy = 1
        y1 = y1 + dy
        y2 = y2 + dy
        y3 = y3 + dy
    else:
        dy = 0
    A = [[x1, y1, 1, 1, 0, 0],[x2, y2, 1, 0, 1, 0],[x3, y3, 1, 0, 0, 1]]
#    print(A)
    for i in range(3):
        A[0] = [x/A[0][0] for x in A[0]]
        A[1] = [A[1][j] - A[1][0] * A[0][j] for j in range(6)]
        A[2] = [A[2][j] - A[2][0] * A[0][j] for j in range(6)]
#        print(A)
        for j in range(3):
            A[j] = A[j][1:] + A[j][:1]
        A = A[1:] + A[:1]
#        print(A)
    for i in range(3):
        A[i] = A[i][:3]
#    print(A)
    V = [-x1**2-y1**2, -x2**2-y2**2, -x3**2-y3**2]
    M = [(A[i][0] * V[0] + A[i][1] * V[1] + A[i][2] * V[2]) for i in range(3)]
    xcenter = -0.5 * M[0] - dx
    ycenter = -0.5 * M[1] - dy
    radius = sqrt((M[0]**2) /4 + (M[1]**2) /4 - M[2])
    return xcenter, ycenter, radius

n = int(input())
for line in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    xc, yc, ra = circle(x1, y1, x2, y2, x3, y3)
    print('%.3f %.3f %.3f' % (xc, yc, ra))

Submission status: Accepted

Solution code:
import math

n = int(raw_input())

for i in range(n):

  x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())

  px = ((y2 - y3)*(x1*x1 + y1*y1) + (y3 - y1)*(x2*x2 + y2*y2) + (y1 - y2)*(x3*x3 + y3*y3))/(2*(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)))
  py = ((x2 - x3)*(x1*x1 + y1*y1) + (x3 - x1)*(x2*x2 + y2*y2) + (x1 - x2)*(x3*x3 + y3*y3))/(2*(y1*(x2 - x3) + y2*(x3 - x1) + y3*(x1 - x2)))

  r = math.sqrt(pow((x1 - px), 2) + pow((y1 - py), 2))

  print "%.3f %.3f %.3f" % (px, py, r)

Submission status: Accepted

Solution code:
import math

def solve(a,b,c,d,e,f):
	x = - (d*(f**2+e**2-b**2-a**2) + b*(-f**2-e**2) + b**2*f + a**2*f + d**2*(b-f) + c**2*(b-f)) / (c*(2*f-2*b) - 2*a*f + 2*b*e + d*(2*a-2*e))
	y = (c*(f**2+e**2-b**2-a**2) + a*(-f**2-e**2) + b**2*e + a**2*e + d**2*(a-e) + c**2*(a-e)) / (c*(2*f-2*b) - 2*a*f + 2*b*e + d*(2*a - 2*e))
	r = math.hypot(x-a, y-b) 
	return x,y,r

n = int(input())
for _ in range(n):
	a,b,c,d,e,f = map(float, input().split())
	x,y,r = solve(a,b,c,d,e,f)
	print("{:.3f} {:.3f} {:.3f}".format(x, y, 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())
    a1,b1,c1 = 2*(x2-x1),2*(y2-y1), (x1**2 - x2 **2 + y1 ** 2 - y2 ** 2)
    a2,b2,c2 = 2*(x3-x1), 2*(y3-y1), (x1**2 - x3 **2 + y1 ** 2 - y3 ** 2)

    p1 = (b1*c2 - b2*c1)/(a1*b2 - a2*b1)
    p2 = (c1*a2 - c2*a1)/(a1*b2 - a2*b1)
    r = math.hypot(x1-p1, y1-p2)
    temp = [p1,p2,r]
    ans = map(lambda x:round(x,3),temp)
    print("%03.3f %03.3f %03.3f"%(temp[0],temp[1],temp[2]))

Submission status: Accepted

Solution code:
import math

def Cramer(c):
	den = c[0]*c[4] - c[1]*c[3]
	return [(c[2]*c[4] - c[1]*c[5]) / den, (c[0]*c[5] - c[2]*c[3]) / den]

n = eval(input())
for i in range(n):
	c = [eval(item) for item in input().split()]
	sol = Cramer([2*(c[0] - c[2]),\
				  2*(c[1] - c[3]),\
				  c[0]**2 + c[1]**2 - c[2]**2 - c[3]**2,\
				  2*(c[0] - c[4]),\
				  2*(c[1] - c[5]),\
				  c[0]**2 + c[1]**2 - c[4]**2 - c[5]**2])
	r = math.sqrt((sol[0] - c[0])**2+(sol[1] - c[1])**2)
	print('%.3f %.3f %.3f' %(sol[0], sol[1], r))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
for _ in[0]*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:
import math

def simultaneous_equasion(a, b, c, d, e, f):
    "??£???????¨????"
    det = a * d - b * c
    a11 = d / det
    a12 = - b / det
    a21 = - c / det
    a22 = a / det
    return a11 * e + a12 * f, a21 * e + a22 * f

n = int(input())
for i in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    # ?????????O??¨????????¨???OP1 ^ 2 = OP2 ^ 2
    # (x - x1) ^ 2 + (y - y1) ^ 2 = (x - x2) ^ 2 + (y - y2) ^ 2
    # - 2 * x * x1 + x1 ^ 2 - 2 * y * y1 + y1 ^ 2 = - 2 * x * x2 + x2 ^ 2 - 2 * y * y2 + y2 ^ 2
    # 2 * (x1 - x2) * x + 2 * (y1 - y2) * y = x1 ^ 2 + y2 ^ 2 - x2 ^ 2 - y2 ^ 2
    a = 2 * (x1 - x2)
    b = 2 * (y1 - y2)
    c = 2 * (x1 - x3)
    d = 2 * (y1 - y3)
    e = x1 ** 2 + y1 ** 2 - x2 ** 2 - y2 ** 2
    f = x1 ** 2 + y1 ** 2 - x3 ** 2 - y3 ** 2
    px, py = simultaneous_equasion(a, b, c, d, e, f)
    r = math.sqrt((px - x1) ** 2 + (py - y1) ** 2)
    print("%.3f %.3f %.3f" % (round(px, 3), round(py, 3), round(r, 3)))

Submission status: Accepted

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

import sys

def length(a, b):
    return ((a[0] - b[0])**2 + (a[1] - b[1])**2)**0.5

def solve_sim_equ(a, b, c, d, e, f):
    '''
    From Problem 0004.
    This function solves following equation.
    ax + by = c
    dx + ey = f
    '''
    if a==0 and d==0:
        if b==0 and e==0:
            return 0., 0.
        if b != 0:
            return 0., c/b+0.
        else:
            return 0., f/e+0.
    elif b==0 and e==0:
        if a != 0:
            return 0., d/a+0.
        else:
            return 0., a/d+0.

    if b == 0:
        a, d = d, a
        b, e = e, b
        c, f = f, c
    g = e / b
    x = (g*c - f) / (g*a - d)
    y = (c - a*x) / b
    return x+0., y+0.


def circumscribed_circle(x, y, z):
    def get_equ_coef(p, q):
        h_x = (p[0] + q[0]) / 2
        h_y = (p[1] + q[1]) / 2
        a = q[1] - p[1]
        b = p[0] - q[0]
        c = b * h_x - a * h_y
        return b, -a, c
    coef = get_equ_coef(x, y) + get_equ_coef(y, z)
    center = solve_sim_equ(*coef)
    r = length(center, x)
    return center, r


def main():
    N = int(input())
    for i in range(N):
        vs = [float(v) for v in input().split()]
        a = (vs[0], vs[1])
        b = (vs[2], vs[3])
        c = (vs[4], vs[5])
        center, r = circumscribed_circle(a, b, c)
        print('{0:.3f} {1:.3f} {2:.3f}'.format(center[0], center[1], r))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

n=int(input())
for i in range(n):
    deta=[float(i) for i in input().split()]
    h1=math.sqrt((deta[2]-deta[0])**2+(deta[3]-deta[1])**2)
    h2=math.sqrt((deta[4]-deta[2])**2+(deta[5]-deta[3])**2)
    h3=math.sqrt((deta[0]-deta[4])**2+(deta[1]-deta[5])**2)
    sub=(h1+h2+h3)/2
    s=math.sqrt(sub*(sub-h1)*(sub-h2)*(sub-h3))
    sum=((h1*h2*h3)/s)/4
    a=2*deta[2]-2*deta[0]
    b=2*deta[3]-2*deta[1]
    c=-(deta[0]**2+deta[1]**2-(deta[2]**2)-(deta[3]**2))
    d=2*deta[4]-2*deta[2]
    e=2*deta[5]-2*deta[3]
    f=-(deta[2]**2+deta[3]**2-(deta[4]**2)-(deta[5]**2))
    
    x=(e*c-b*f)/(a*e-b*d)
    y=(a*f-c*d)/(a*e-b*d)
    print("{0:.3f} {1:.3f} {2:.3f}".format(x,y,sum))

Submission status: Accepted

Solution code:
import math

n = input()
for i in xrange(n):
    x1, y1, x2, y2, x3, y3 = map(float, raw_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)-2*(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)-2*(x1-x2)*(y1-y3))

    print '%.3f %.3f %.3f'%(round(p,3), round(q,3), round(math.sqrt((x1-p)**2+(y1-q)**2), 3))

Submission status: Accepted

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

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())
    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 - f*b)/(a*e - b*d)
    y = (c*d - f*a)/(b*d - e*a)
    r = math.sqrt((x1 - x)**2 + (y1 - y)**2)
    x = round(x,3)
    y = round(y,3)
    r = round(r,3)
    if x == -0.0:
        x = 0.0
    if y == -0.0:
        y = 0.0
    print("{0:.3f}".format(x),end = ' ')
    print("{0:.3f}".format(y),end = ' ')
    print("{0:.3f}".format(r))

Submission status: Accepted

Solution code:
from math import cos, sin, sqrt, radians, degrees, acos, fabs

if __name__ == '__main__':
    epsilon = 1e-9

    # ??????????????\???
    num = int(input())
    for i in range(num):
        x1, y1, x2, y2, x3, y3 = [float(x) for x in input().split(' ')]

        # ??????????????§????§???¢???cos???????±???????arccos??§?§???????????????????
        a = sqrt((x1-x2)**2 + (y1-y2)**2)
        b = sqrt((x2-x3)**2 + (y2-y3)**2)
        c = sqrt((x1-x3)**2 + (y1-y3)**2)
        cosA = (b**2+c**2-a**2)/(2*b*c)

        # ???????§???????????????°?????£????????????????????\????????????????±????????????¨?????§?????????
        r = a / sin(acos(cosA)) / 2

        """
       ??????O?????§?¨????(x, y)??¨????????¨
       (x-x1)**2 + (y-y1)**2 = (x-x2)**2 + (y-y2)**2
       x**2 -2*x1*x + x1**2 + y**2 -2*y1*y + y1**2 = ... -2*x2*x, x2**2, -2*y2*y, y2**2
       ?????¨????????¨ (-2*x1 + 2*x2)x + (-2y1 + 2*y2)y + (x1**2 + y1**2 - x2**2 - y2**2) = 0
       x1, x3???????????????????§????
       (-2*x1 + 2*x3)x + (-2y1 + 2*y3)y + (x1**2 + y1**2 - x3**2 - y3**2) = 0
       """
        A = -2*x1 + 2*x2
        B = -2*y1 + 2*y2
        C = -2*x1 + 2*x3
        D = -2*y1 + 2*y3
        E = x1**2 + y1**2 - x2**2 - y2**2
        F = x1**2 + y1**2 - x3**2 - y3**2

        x = 1/(A*D-B*C) * (D*E - B*F)
        y = 1/(A*D-B*C) * (-C*E + A*F)
        # ?¨????????????¨?????? -0.0 ???????????´???????????¶?????? 0.0 ?????????
        if fabs(x) < epsilon:
            x = 0.0
        if fabs(y) < epsilon:
            y = 0.0

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

Submission status: Accepted

Solution code:
from math import sqrt, fabs


def calcu_cirucumcenter(x1, y1, x2, y2, x3, y3):
    """
   ??????O?????§?¨????(x, y)??¨????????¨
   (x-x1)**2 + (y-y1)**2 = (x-x2)**2 + (y-y2)**2
   x**2 -2*x1*x + x1**2 + y**2 -2*y1*y + y1**2 = ... -2*x2*x, x2**2, -2*y2*y, y2**2
   ?????¨????????¨ (-2*x1 + 2*x2)x + (-2y1 + 2*y2)y + (x1**2 + y1**2 - x2**2 - y2**2) = 0
   x1, x3???????????????????§????
   (-2*x1 + 2*x3)x + (-2y1 + 2*y3)y + (x1**2 + y1**2 - x3**2 - y3**2) = 0
   
   ??????????????¢????????\????????¢???????????£???????¨??????¨???????§£???
   | a b | = |e|
   | c d |   |f|
   """
    a = -2 * x1 + 2 * x2
    b = -2 * y1 + 2 * y2
    c = -2 * x1 + 2 * x3
    d = -2 * y1 + 2 * y3
    e = -1* (x1 ** 2 + y1 ** 2 - x2 ** 2 - y2 ** 2)
    f = -1 * (x1 ** 2 + y1 ** 2 - x3 ** 2 - y3 ** 2)

    x = 1 / (a * d - b * c) * (d * e - b * f)
    y = 1 / (a * d - b * c) * (-c * e + a * f)
    return x, y


if __name__ == '__main__':
    epsilon = 1e-9

    # ??????????????\???
    num = int(input())
    for i in range(num):
        x1, y1, x2, y2, x3, y3 = [float(x) for x in input().split(' ')]

        # ?????\????????????(??????)????±???????
        x, y = calcu_cirucumcenter(x1, y1, x2, y2, x3, y3)
        # ?¨????????????¨?????? -0.0 ???????????´???????????¶?????? 0.0 ?????????
        if fabs(x) < epsilon:
            x = 0.0
        if fabs(y) < epsilon:
            y = 0.0

        # ????????????????????§????????¢?????????
        r = sqrt((x - x1)**2 + (y - y1)**2)

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

Submission status: Accepted

Solution code:
n = int(input())
datasets = [0]*n
#datasets[k] == [x1k,y1k,x2k,y2k,x3k,y3k]
for i in range(0,n):
  datasets[i] = list(map(float,input().split()))

for data in datasets:
  x1p2=(data[0]+data[2])
  x1m2=(data[0]-data[2])
  x1p3=(data[0]+data[4])
  x1m3=(data[0]-data[4])
  y1p2=(data[1]+data[3])
  y1m2=(data[1]-data[3])
  y1p3=(data[1]+data[5])
  y1m3=(data[1]-data[5])
  x=(x1p2*x1m2*y1m3+y1p2*y1m2*y1m3-x1p3*x1m3*y1m2-y1p3*y1m3*y1m2)/(2*(x1m2*y1m3-x1m3*y1m2))
  y=(y1p2*y1m2*x1m3+x1p2*x1m2*x1m3-y1p3*y1m3*x1m2-x1p3*x1m3*x1m2)/(2*(y1m2*x1m3-y1m3*x1m2))
  r=((x-data[0])**2+(y-data[1])**2)**(1/2)
  if x == 0.000:
    x=0
  if y == 0.000:
    y=0
  print("{0:.3f} {1:.3f} {2:.3f}".format(x,y,r))

Submission status: Accepted

Solution code:
class vertex(object):
    def __init__(self,a):
        self.x=a[0]
        self.y=a[1]
class circle(object):
    def __init__(self,p,r):
        self.px=p.x
        self.py=p.y
        self.r=r
class triangle(object):
    def __init__(self,a,b,c):
        self.a=a
        self.b=b
        self.c=c
        import math
        self.ab=math.sqrt((self.a.x-self.b.x)**2+(self.a.y-self.b.y)**2)
        self.bc=math.sqrt((self.b.x-self.c.x)**2+(self.b.y-self.c.y)**2)
        self.ca=math.sqrt((self.c.x-self.a.x)**2+(self.c.y-self.a.y)**2)
        c=self.ab
        a=self.bc
        b=self.ca
        self.cosA=(b**2+c**2-a**2)/(2*b*c)
        self.cosB=(a**2+c**2-b**2)/(2*a*c)
        self.cosC=(b**2+a**2-c**2)/(2*b*a)
        self.sinA=math.sqrt(1-self.cosA**2)
        self.sinB=math.sqrt(1-self.cosB**2)
        self.sinC=math.sqrt(1-self.cosC**2)
        self.sin2A=2*self.sinA*self.cosA
        self.sin2B=2*self.sinB*self.cosB
        self.sin2C=2*self.sinC*self.cosC
    def area(self):
        import math
        s=(self.ab+self.bc+self.ca)/2
        S=math.sqrt(s*(s-self.ab)*(s-self.bc)*(s-self.ca))
        return S
    def circumscribed(self):
        R=self.ab/(2*self.sinC)
        px=(self.sin2A*self.a.x+self.sin2B*self.b.x+self.sin2C*self.c.x)/(self.sin2A+self.sin2B+self.sin2C)
        py=(self.sin2A*self.a.y+self.sin2B*self.b.y+self.sin2C*self.c.y)/(self.sin2A+self.sin2B+self.sin2C)
        px=round(px,3)
        py=round(py,3)
        R=round(R,3)
        p=vertex((px,py))
        return circle(p,R)
n=eval(input())
p1=[]
p2=[]
p3=[]
for i in range(n):
    a,b,c,d,e,f=list(map(float,input().split()))
    p1.append(vertex((a,b)))
    p2.append(vertex((c,d)))
    p3.append(vertex((e,f)))
for i in range(n):
    Triangle=triangle(p1[i],p2[i],p3[i])
    Circle=Triangle.circumscribed()
    print('%.3f %.3f %.3f'%(Circle.px,Circle.py,Circle.r))

Submission status: Accepted

Solution code:
import math
for _ in range(int(input())):
    x1,y1,x2,y2,x3,y3=map(float,input().split())
    a,b,c=2*(x2-x1),2*(y2-y1),x1**2-x2**2+y1**2-y2**2
    aa,bb,cc=2*(x3-x1),2*(y3-y1),x1**2-x3**2+y1**2-y3**2
    x,y=(b*cc-bb*c)/(a*bb-aa*b),(c*aa-cc*a)/(a*bb-aa*b)
    print('%.3f %.3f %.3f'%(x,y,math.hypot(x1-x,y1-y)))

Submission status: Accepted

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

import sys
import math

def solve(x1,y1,x2,y2,x3,y3):
    z1 = -1 * (x1**2 + y1**2)
    z2 = -1 * (x2**2 + y2**2)
    z3 = -1 * (x3**2 + y3**2)

    a11,a12,a13 = x1,y1,1
    a21,a22,a23 = x2,y2,1
    a31,a32,a33 = x3,y3,1
    det = a11*a22*a33 + a21*a32*a13 + a31*a12*a23 - a11*a32*a23 - a31*a22*a13 - a21*a12*a33

    l = ((a22*a33 - a23*a32)*z1 + (a13*a32 - a12*a33)*z2 + (a12*a23 - a13*a22)*z3)/det
    m = ((a23*a31 - a21*a33)*z1 + (a11*a33 - a13*a31)*z2 + (a13*a21 - a11*a23)*z3)/det
    n = ((a21*a32 - a22*a31)*z1 + (a12*a31 - a11*a32)*z2 + (a11*a22 - a12*a21)*z3)/det

    x,y,r = round(-l/2,3),round(-m/2,3),round(math.sqrt((l**2)/4+(m**2)/4-n),3)
    sol = [x, y, r]
    return sol


n,count = int(input()),0
array = []
for i in sys.stdin:
    array.append(i)
    count += 1
    if count == n:
        break

    
for i in range(len(array)):
    x = array[i]
    p = x.split()
    res = solve(float(p[0]),float(p[1]),float(p[2]),float(p[3]),float(p[4]),float(p[5]))
    print('{:.3f} {:.3f} {:.3f}'.format(res[0], res[1], res[2]))

Submission status: Accepted

Solution code:
import sys
import math

def to_f(e):
  return float(e)

n = int(raw_input().rstrip())
for i in range(n):
  line = raw_input().rstrip() 
  x1, y1, x2, y2, x3, y3 = map(to_f, line.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
  xp = (b1*c2-b2*c1)/(a1*b2-a2*b1)
  yp = (c1*a2-c2*a1)/(a1*b2-a2*b1)
  r  = round(math.sqrt((xp-x1)**2+(yp-y1)**2), 3)
  #print(str(xp.format()+ " " + str(yp) + " " + str(r))
  print "%.3f %.3f %.3f" % (xp, yp, r)

Submission status: Accepted

Solution code:
for i in range(int(input())):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    c = (x1-x2)**2 + (y1-y2)**2
    a = (x2-x3)**2 + (y2-y3)**2
    b = (x3-x1)**2 + (y3-y1)**2
    # 16s^2
    s = 2*(a*b + b*c + c*a) - (a*a + b*b + c*c)

    px = (a*(b+c-a)*x1 + b*(c+a-b)*x2 + c*(a+b-c)*x3) / s
    py = (a*(b+c-a)*y1 + b*(c+a-b)*y2 + c*(a+b-c)*y3) / s

    ar = a**0.5
    br = b**0.5
    cr = c**0.5

    r = ar*br*cr / ((ar+br+cr)*(-ar+br+cr)*(ar-br+cr)*(ar+br-cr))**0.5

    print("{:>.3f}".format(px),"{:>.3f}".format(py),"{:>.3f}".format(r))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys

n = int(sys.stdin.readline())
for i in range(n):
    x1,y1,x2,y2,x3,y3 = list(map(float, sys.stdin.readline().split()))
    a = ((x3-x2)**2 + (y3-y2)**2)**0.5
    b = ((x1-x3)**2 + (y1-y3)**2)**0.5
    c = ((x2-x1)**2 + (y2-y1)**2)**0.5
    r = a*b*c / ((a+b+c) * (-a+b+c) * (a-b+c) * (a+b-c))**0.5
    a2,b2,c2 = a**2,b**2,c**2
    x = (a2*(b2+c2-a2)*x1 + b2*(c2+a2-b2)*x2 + c2*(a2+b2-c2)*x3) / \
        (a2*(b2+c2-a2) + b2*(c2+a2-b2) + c2*(a2+b2-c2))
    y = (a2*(b2+c2-a2)*y1 + b2*(c2+a2-b2)*y2 + c2*(a2+b2-c2)*y3) / \
        (a2*(b2+c2-a2) + b2*(c2+a2-b2) + c2*(a2+b2-c2))
    print("{:.3f} {:.3f} {:.3f}".format(x,y,r))

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 fractions


def calc(x1, y1, x2, y2):
    return 2 * (x2 - x1), 2 * (y2 - y1), x2 ** 2 + y2 ** 2 - x1 ** 2 - y1 ** 2


n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    cx1, cy1, z1 = calc(x1, y1, x2, y2)
    cx2, cy2, z2 = calc(x1, y1, x3, y3)
    gcd = fractions.gcd(cx1, cx2)
    r1, r2 = cx2 // gcd, cx1 // gcd
    dcy = r1 * cy1 - r2 * cy2
    dz = r1 * z1 - r2 * z2
    y = dz / dcy
    try:
        x = (z1 - cy1 * y) / cx1
    except ZeroDivisionError:
        x = (z2 - cy2 * y) / cx2
    r = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
    print(*map(lambda x: '{:.3f}'.format(round(x, 3)), (x, y, r)))

Submission status: Accepted

Solution code:
import fractions


def calc(x1, y1, x2, y2):
    return 2 * (x2 - x1), 2 * (y2 - y1), x2 ** 2 + y2 ** 2 - x1 ** 2 - y1 ** 2


n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    cx1, cy1, z1 = calc(x1, y1, x2, y2)
    cx2, cy2, z2 = calc(x1, y1, x3, y3)
    gcd = fractions.gcd(cx1, cx2)
    r1, r2 = cx2 // gcd, cx1 // gcd
    dcy = r1 * cy1 - r2 * cy2
    dz = r1 * z1 - r2 * z2
    y = dz / dcy
    x = (z1 - cy1 * y) / cx1 if cx1 else (z2 - cy2 * y) / cx2
    r = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
    print('{:.3f} {:.3f} {:.3f}'.format(x, y, r))

Submission status: Accepted

Solution code:
def calc(x1, y1, x2, y2):
    return 2 * (x2 - x1), 2 * (y2 - y1), x2 ** 2 + y2 ** 2 - x1 ** 2 - y1 ** 2


n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    cx1, cy1, z1 = calc(x1, y1, x2, y2)
    cx2, cy2, z2 = calc(x1, y1, x3, y3)
    dcy, dz = cx2 * cy1 - cx1 * cy2, cx2 * z1 - cx1 * z2
    y = dz / dcy
    x = (z1 - cy1 * y) / cx1 if cx1 else (z2 - cy2 * y) / cx2
    r = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
    print('{:.3f} {:.3f} {:.3f}'.format(x, y, 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(pow(x3-x2, 2) + pow(y3-y2, 2), 0.5)
    b = pow(pow(x1-x3, 2) + pow(y1-y3, 2), 0.5)
    c = pow(pow(x2-x1, 2) + pow(y2-y1, 2), 0.5)
    cosA = (b**2+c**2-a**2) / (2*b*c)
    sinA = 1-cosA**2
    r = a / pow(sinA, 0.5) / 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)
    print("{0:.3f} {1:.3f} {2:.3f}".format(-l/2, -m/2, r))

Submission status: Accepted

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

import sys
import os
import math


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

    c = 2 * ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1))
    x = ((y3 - y1) * (x2 ** 2 - x1 ** 2 + y2 ** 2 - y1 ** 2) + (y1 - y2) * (x3 ** 2 - x1 ** 2 + y3 ** 2 - y1 ** 2)) / c
    y = ((x1 - x3) * (x2 ** 2 - x1 ** 2 + y2 ** 2 - y1 ** 2) + (x2 - x1) * (x3 ** 2 - x1 ** 2 + y3 ** 2 - y1 ** 2)) / c
    r = math.sqrt((x1 - x) ** 2 + (y1 - y) ** 2)

    print("{:.3f} {:.3f} {:.3f}".format(x, y, 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()) # Get variables
	a = 2 * (x2 - x1)
	b = 2 * (y2 - y1)
	c = math.pow(x2, 2) + math.pow(y2, 2) - math.pow(x1, 2) - math.pow(y1, 2)
	d = 2 * (x3 - x1)
	e = 2 * (y3 - y1)
	f = math.pow(x3, 2) + math.pow(y3, 2) - math.pow(x1, 2) - math.pow(y1, 2)
	px = (c * e - b * f) / (a * e - b * d)
	py = (a * f - c * d) / (a * e - b * d)
	r = math.sqrt(math.pow(x1 - px, 2) + math.pow(y1 - py, 2))
	print('{:.3f}'.format(px) + ' ' + '{:.3f}'.format(py) + ' ' + '{:.3f}'.format(r))

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())

for i in range(n):
    l = input()
    x1,y1,x2,y2,x3,y3=map(float,l.split(' '))
    a_2 = (x1 - x2)**2 + (y1 - y2)**2
    b_2 = (x2 - x3)**2 + (y2 - y3)**2
    c_2 = (x3 - x1)**2 + (y3 - y1)**2
    cos_a_2 = (b_2 + c_2 - a_2)**2/(4* b_2 * c_2)
    sin_a_2 = 1 - cos_a_2
    r = round(sqrt(a_2/sin_a_2)/2,3)
    a = (x1**2 - x3**2 + y1**2 - y3**2)*(x2 - x1)
    b = (x1**2 - x2**2 + y1**2 - y2**2)*(x3 - x1)
    c = (y2 - y1)*(x3 - x1)
    d = (y3 - y1)*(x2 - x1)
    py = round((a-b)/(c-d)/2,3)
    a = (x1**2 - x3**2 + y1**2 - y3**2)*(y2 - y1)
    b = (x1**2 - x2**2 + y1**2 - y2**2)*(y3 - y1)
    c = (x2 - x1)*(y3 - y1)
    d = (x3 - x1)*(y2 - y1)
    px = round((a-b)/(c-d)/2,3)
    print('%.3f %.3f %.3f' %(px, py, r))

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())

for i in range(n):
    l = input()
    x1,y1,x2,y2,x3,y3=map(float,l.split(' '))
    a_2 = (x1 - x2)**2 + (y1 - y2)**2
    b_2 = (x2 - x3)**2 + (y2 - y3)**2
    c_2 = (x3 - x1)**2 + (y3 - y1)**2
    cos_a_2 = (b_2 + c_2 - a_2)**2/(4* b_2 * c_2)
    sin_a_2 = 1 - cos_a_2
    r = round(sqrt(a_2/sin_a_2)/2,3)
    a = (x1**2 - x3**2 + y1**2 - y3**2)*(x2 - x1)
    b = (x1**2 - x2**2 + y1**2 - y2**2)*(x3 - x1)
    c = (y2 - y1)*(x3 - x1)
    d = (y3 - y1)*(x2 - x1)
    py = round((a-b)/(c-d)/2,3) + 0
    a = (x1**2 - x3**2 + y1**2 - y3**2)*(y2 - y1)
    b = (x1**2 - x2**2 + y1**2 - y2**2)*(y3 - y1)
    c = (x2 - x1)*(y3 - y1)
    d = (x3 - x1)*(y2 - y1)
    px = round((a-b)/(c-d)/2,3) + 0
    print('%.3f %.3f %.3f' %(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())
    a1,b1,c1 = 2*(x2-x1),2*(y2-y1), (x1**2 - x2 **2 + y1 ** 2 - y2 ** 2)
    a2,b2,c2 = 2*(x3-x1), 2*(y3-y1), (x1**2 - x3 **2 + y1 ** 2 - y3 ** 2)
 
    p1 = (b1*c2 - b2*c1)/(a1*b2 - a2*b1)
    p2 = (c1*a2 - c2*a1)/(a1*b2 - a2*b1)
    r = math.hypot(x1-p1, y1-p2)
    temp = [p1,p2,r]
    ans = map(lambda x:round(x,3),temp)
    print("%03.3f %03.3f %03.3f"%(temp[0],temp[1],temp[2]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
import math
 
num = int(input())
for i in range(num):
    x1,y1,x2,y2,x3,y3 = map(float,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)
 
    p1 = (b1*c2 - b2*c1) / (a1*b2 - a2*b1)
    p2 = (c1*a2 - c2*a1) / (a1*b2 - a2*b1)
    r = math.hypot(x1-p1, y1-p2)
    temp = [p1,p2,r]
    ans = map(lambda x:round(x,3),temp)
    print("%03.3f %03.3f %03.3f"%(temp[0],temp[1],temp[2]))

Submission status: Accepted

Solution code:
import sys
import math
n = int(sys.stdin.readline().rstrip())
for i in range(n):
    x1,y1,x2,y2,x3,y3 = map(float, sys.stdin.readline().rstrip().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)-2*(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)-2*(x1-x2)*(y1-y3))
    r = math.sqrt((p-x1)**2 + (q-y1)**2)
    print("{:0.3f} {:0.3f} {:0.3f}".format(round(p,3),round(q,3),round(r,3)))

Submission status: Accepted

Solution code:
p = int(input())
for i in range(p):
    x1, y1, x2, y2, x3, y3 = map(float, input().split(" "))
    xa, ya, xb, yb = x2-x1, y2-y1, x3-x1, y3-y1
    a = complex(xa, ya)
    b = complex(xb, yb)
    z0 = abs(a) ** 2 * b - abs(b) **2 * a
    z0 /= a.conjugate() * b - a * b.conjugate()

    z = z0 + complex(x1, y1)
    zx = "{0:.3f}".format(z.real)
    zy = "{0:.3f}".format(z.imag)
    r = "{0:.3f}".format(abs(z0))
    print(zx, zy, r)

Submission status: Accepted

Solution code:
from math import acos
from math import sin

def ang(ax, ay, ox, oy, bx, by):
    oax, oay = ax - ox, ay - oy
    obx, oby = bx - ox, by - oy
    r1, r2 = oax ** 2 + oay ** 2, obx ** 2 + oby ** 2
    return acos((oax * obx + oay * oby) / (r1 * r2) ** 0.5)

def circumcircle(x1, y1, x2, y2, x3, y3):
    s2A = sin(2 * ang(x3, y3, x1, y1, x2, y2))
    s2B = sin(2 * ang(x1, y1, x2, y2, x3, y3))
    s2C = sin(2 * ang(x2, y2, x3, y3, x1, y1))
    px = (s2A * x1 + s2B * x2 + s2C * x3) / (s2A + s2B + s2C) + 0.
    py = (s2A * y1 + s2B * y2 + s2C * y3) / (s2A + s2B + s2C) + 0.
    r = (((x2 - x3) ** 2 + (y2 - y3) ** 2) ** 0.5) / (2 * sin(ang(x2, y2, x1, y1, x3, y3))) + 0.
    return px, py, r

n = int(input())
for i in range(n):
    print("{0[0]:.3f} {0[1]:.3f} {0[2]:.3f}".format(
          circumcircle(*tuple(map(float, input().split())))))