Problem:
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

Solution (Python):
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))

Solution (Python):
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)))

Solution (Python):


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]))

Solution (Python):
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 "%.3f %.3f %.3f" % (xp, yp, r)

Solution (Python):
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
    
    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))

Solution (Python):


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))

Solution (Python):
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)

Solution (Python):
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)))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):


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))

Solution (Python):
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 = 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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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]))

Solution (Python):


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]))

Solution (Python):
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)))

Solution (Python):
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)

Solution (Python):
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())))))

Solution (Python):


import sys, math, os


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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):

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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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

Solution (Python):
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)))

Solution (Python):
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))

Solution (Python):
import math

N = int(input())

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

    
    

    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'))

Solution (Python):
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}")

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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)))

Solution (Python):
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)

Solution (Python):
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)))

Solution (Python):
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}')

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):

from math import sqrt



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_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 = [[-(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)]
    
    
    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))

Solution (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)

Solution (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)

Solution (Python):
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)

Solution (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())))

Solution (Python):
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]]))

Solution (Python):
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]]))

Solution (Python):
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]]))