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):
n = int(input())
for i in range(n):
    x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
    a = 2*(x1-x2)
    b = 2*(y1-y2)
    c = x1**2 - x2**2 + y1**2 - y2**2
    d = 2*(x1-x3)
    e = 2*(y1-y3)
    f = x1**2 - x3**2 + y1**2 - y3**2

    y = (c*d - a*f) / (b*d - a*e)
    if a==0:
        x = (f - e*y) / d
    else:
        x = (c - b*y) / a
    
    r = ((x1 - x)**2 + (y1 - y)**2)**0.5
    print('{:.3f}'.format(round(x, 3)), end=" ")
    print('{:.3f}'.format(round(y, 3)), end=" ")
    print('{:.3f}'.format(round(r, 3)))

Solution (Python):
import math
 
n = int(input())
positions = []
for i in range(n):
  positions.append(list(map(float, input().split())))
  
for i in range(n):
  ra = [positions[i][0],positions[i][1]]
  rb = [positions[i][2],positions[i][3]]
  rc = [positions[i][4],positions[i][5]]
 
  A = (rb[0]-rc[0])**2+(rb[1]-rc[1])**2
  B = (rc[0]-ra[0])**2+(rc[1]-ra[1])**2
  C = (ra[0]-rb[0])**2+(ra[1]-rb[1])**2
 
  P = A * (B+C-A)
  Q = B * (C+A-B)
  R = C * (A+B-C)
 
  rcc_x = (P*ra[0] + Q*rb[0] + R*rc[0]) / (P+Q+R)
  rcc_y = (P*ra[1] + Q*rb[1] + R*rc[1]) / (P+Q+R)
 
  radius = math.sqrt((rcc_x-positions[i][0])**2+(rcc_y-positions[i][1])**2)
  print("{0:.3f} {1:.3f} {2:.3f}".format(rcc_x,rcc_y,radius))

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 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):
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,math
if sys.version_info[0]>=3: raw_input=input
N=int(raw_input())
for i in range(N):
    x1,y1,x2,y2,x3,y3=[float(e) for e in raw_input().split()]
    a1=2*x2-2*x1
    b1=2*y2-2*y1
    c1=x1*x1-x2*x2+y1*y1-y2*y2
    a2=2*x3-2*x1
    b2=2*y3-2*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)
    print('%.3f %.3f %.3f'%(x,y,math.hypot(x1-x,y1-y)))

Solution (Python):
import math
n=int(input())
for i in range(n):
  x1,y1,x2,y2,x3,y3=map(float,input().split())
  a=(x3-x1)*(x1**2+y1**2-x2**2-y2**2)-(x2-x1)*(x1**2+y1**2-x3**2-y3**2)
  b=2*(x3-x1)*(y1-y2)-2*(x2-x1)*(y1-y3)
  py=a/b
  if x2-x1!=0:
    px=(2*(y1-y2)*py-x1**2-y1**2+x2**2+y2**2)/(2*(x2-x1))
  else:
    px=(2*(y1-y3)*py-x1**2-y1**2+x3**2+y3**2)/(2*(x3-x1))
  r=math.sqrt((px-x1)**2+(py-y1)**2)
  print(f"{px:.3f}",f"{py:.3f}",f"{r:.3f}")

Solution (Python):
import math

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

for i in range(n):
  ra = [positions[i][0],positions[i][1]]
  rb = [positions[i][2],positions[i][3]]
  rc = [positions[i][4],positions[i][5]]

  A = (rb[0]-rc[0])**2+(rb[1]-rc[1])**2
  B = (rc[0]-ra[0])**2+(rc[1]-ra[1])**2
  C = (ra[0]-rb[0])**2+(ra[1]-rb[1])**2

  P = A * (B+C-A)
  Q = B * (C+A-B)
  R = C * (A+B-C)

  rcc_x = (P*ra[0] + Q*rb[0] + R*rc[0]) / (P+Q+R)
  rcc_y = (P*ra[1] + Q*rb[1] + R*rc[1]) / (P+Q+R)

  radius = math.sqrt((rcc_x-positions[i][0])**2+(rcc_y-positions[i][1])**2)
  print("{0:.3f} {1:.3f} {2:.3f}".format(rcc_x,rcc_y,radius))

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP
n=int(input())
for i in range(n):
    x1,y1,x2,y2,x3,y3=map(float,input().split())
    a=2*(x1-x2)
    b=2*(y1-y2)
    c=x1**2+y1**2-x2**2-y2**2
    d=2*(x1-x3)
    e=2*(y1-y3)
    f=x1**2+y1**2-x3**2-y3**2
    x=(c*e-b*f)/(a*e-b*d)+0.0
    y=(c*d-a*f)/(b*d-a*e)+0.0
    r=((x-x1)**2+(y-y1)**2)**0.5
    print(Decimal(str(x)).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP),Decimal(str(y)).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP),Decimal(str(r)).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP))

Solution (Python):
n = int(input())
import math
for _ in range(n):
    ax,ay,bx,by,cx,cy = [float(i) for i in input().split()]
    ab = math.sqrt((ax-bx)**2+(ay-by)**2)
    bc = math.sqrt((bx-cx)**2+(by-cy)**2)
    ca = math.sqrt((cx-ax)**2+(cy-ay)**2)
    cos_a = (ab**2+ca**2-bc**2)/(2*ab*ca)
    sin_a = math.sqrt(1-cos_a**2)
    r = bc/(2*sin_a)
    px = ((ay-cy)*(ay**2 -by**2 +ax**2 -bx**2) -(ay-by)*(ay**2 -cy**2 +ax**2 -cx**2)) / (2*(ay-cy)*(ax-bx)-2*(ay-by)*(ax-cx))
    py = ((ax-cx)*(ax**2 -bx**2 +ay**2 -by**2) -(ax-bx)*(ax**2 -cx**2 +ay**2 -cy**2)) / (2*(ax-cx)*(ay-by)-2*(ax-bx)*(ay-cy))
    def round3(x):
        x_ = x*10**3
        if x_%1 < 0.5:
            x_ = math.floor(x_)
        else:
            x_ = math.ceil(x_)
        return x_*10**(-3)
        
            
    print("{:.3f} {:.3f} {:.3f}".format(round3(px),round3(py),round3(r)))

Solution (Python):
import math
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP

n = int(input())

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

    a2 = (x2-x3)**2 + (y2-y3)**2
    b2 = (x1-x3)**2 + (y1-y3)**2
    c2 = (x1-x2)**2 + (y1-y2)**2
    area = ((x2-x1) * (y3-y1) - (x3-x1) * (y2-y1)) / 2

    x = (a2*(b2+c2-a2)*x1 + b2*(c2+a2-b2) *
         x2 + c2*(a2+b2-c2)*x3) / (16*area*area)
    y = (a2*(b2+c2-a2)*y1 + b2*(c2+a2-b2) *
         y2 + c2*(a2+b2-c2)*y3) / (16*area*area)
    r = ((x1-x)**2 + (y1-y)**2)**0.5

    x = Decimal(str(x)).quantize(Decimal("0.001"), rounding=ROUND_HALF_UP)
    y = Decimal(str(y)).quantize(Decimal("0.001"), rounding=ROUND_HALF_UP)
    r = Decimal(str(r)).quantize(Decimal("0.001"), rounding=ROUND_HALF_UP)

    print(x, y, r)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def distance(x1, y1, x2, y2):
    return math.sqrt((x1-x2)**2 + (y1-y2)**2)

def intersection(a1, a2, b1, b2):
    x1,y1 = a1
    x2,y2 = a2
    x3,y3 = b1
    x4,y4 = b2

    ksi = (y4 - y3) * (x4 - x1) - (x4 - x3) * (y4 - y1)
    eta = (x2 - x1) * (y4 - y1) - (y2 - y1) * (x4 - x1)
    delta = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3)
    if delta == 0:
        return None
    ramda = ksi / delta;
    mu = eta / delta;
    if ramda >= 0 and ramda <= 1 and mu >= 0 and mu <= 1:
        return (x1 + ramda * (x2 - x1), y1 + ramda * (y2 - y1))

    return None

def circumcenters(a,b,c):
    t1 = [(a[0]+b[0])/2, (a[1]+b[1])/2]
    s1 = [t1[1]-a[1], a[0]-t1[0]]
    t2 = [(a[0]+c[0])/2, (a[1]+c[1])/2]
    s2 = [t2[1]-a[1], a[0]-t2[0]]
    p1 = [t1[0]+s1[0]*1e7, t1[1]+s1[1]*1e7]
    p2 = [t1[0]-s1[0]*1e7, t1[1]-s1[1]*1e7]
    p3 = [t2[0]+s2[0]*1e7, t2[1]+s2[1]*1e7]
    p4 = [t2[0]-s2[0]*1e7, t2[1]-s2[1]*1e7]
    return intersection(p1,p2,p3,p4)

def main():
    n = I()
    rr = []
    for _ in range(n):
        x1,y1,x2,y2,x3,y3 = LF()
        a = [x1,y1]
        b = [x2,y2]
        c = [x3,y3]
        t = circumcenters(a,b,c)
        rr.append('{:0.3f} {:0.3f} {:0.3f}'.format(t[0], t[1], distance(t[0],t[1],x1,y1)))

    return '\n'.join(rr)


print(main())

Solution (Python):
n = int(input())
for _ in range(n):
    x1,y1,x2,y2,x3,y3 = map(float, input().split())
    gx = (x1+x2+x3)/3
    gy = (y1+y2+y3)/3
    G=( y2*x1-y1*x2 +y3*x2-y2*x3 +y1*x3-y3*x1 )
    Xc= ((x1*x1+y1*y1)*(y2-y3)+(x2*x2+y2*y2)*(y3-y1)+(x3*x3+y3*y3)*(y1-y2))/(2*G)
    Yc=-((x1*x1+y1*y1)*(x2-x3)+(x2*x2+y2*y2)*(x3-x1)+(x3*x3+y3*y3)*(x1-x2))/(2*G)
    r = ( (x1 - Xc) * (x1 - Xc) + (y1 - Yc) * (y1 - Yc) )**0.5
    print("%.3f %.3f %.3f"%(Xc,Yc,r))

Solution (Python):
def circumcenter(vert1, vert2, vert3):
    
    
    Ax, Ay = vert1
    Bx, By = vert2
    Cx, Cy = vert3

    D = 2 * (Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By))
    norm_A = Ax**2 + Ay**2
    norm_B = Bx**2 + By**2
    norm_C = Cx**2 + Cy**2

    Ux = norm_A * (By - Cy) + norm_B * (Cy - Ay) + norm_C * (Ay - By)
    Uy = -(norm_A * (Bx - Cx) + norm_B * (Cx - Ax) + norm_C * (Ax - Bx))

    r = (Ax - Ux/D)*(Ax - Ux/D) + (Ay - Uy/D)* (Ay - Uy/D)
    r = float(r)**0.5
    return [Ux/D, Uy/D, r]

n  = int(input())
for i in range(n):
  xs = list(map(float, input().split()))
  a = circumcenter(xs[0:2], xs[2:4], xs[4:6])
  print(' '.join(map(lambda x:f'{x:0.03f}', a)))

Solution (Python):
n = int(input())
ans = []
for i in range(n):
    ax,ay,bx,by,cx,cy = map(float, input().split(" "))
    a,b,c = 2*(ax-bx),2*(ay-by),(ax+bx)*(ax-bx)+(ay+by)*(ay-by)
    d,e,f = 2*(ax-cx),2*(ay-cy),(ax+cx)*(ax-cx)+(ay+cy)*(ay-cy)
    det = a*e-b*d
    px = (c*e-b*f)/det
    py = (a*f-c*d)/det
    if abs(px) < 1e-4:
        px = 0.0
    if abs(py) < 1e-4:
        py = 0.0
    r = ((ax-px)**2+(ay-py)**2)**(1/2)
    ans.append([px,py,r])
for i in range(n):
    print("{0:.3f}".format(ans[i][0]),"{0:.3f}".format(ans[i][1]),"{0:.3f}".format(ans[i][2]))

Solution (Python):

import math
def simul_eq(a,b,c,d,e,f):
    
    C = [c,f]
    detA = a*e - b*d
    
    At = [[e,-b],[-d,a]]
    x = sum(map((lambda x,y: x*y), At[0], C)) / detA
    y = sum(map((lambda x,y: x*y), At[1], C)) / detA
    fx,fy = '{0:.3f}'.format(x), '{0:.3f}'.format(y)
    if fx == '-0.000': fx = fx[1:]
    if fy == '-0.000': fy = fy[1:]
    return (fx,fy)

n = int(input())
for _ in range(n):
    x1,y1,x2,y2,x3,y3 = map(float, input().split())
    a = math.sqrt(pow(x2-x3, 2) + pow(y2-y3, 2))
    b = math.sqrt(pow(x1-x3, 2) + pow(y1-y3, 2))
    c = math.sqrt(pow(x2-x1, 2) + pow(y2-y1, 2))
    cosA = (pow(b,2) + pow(c,2) - pow(a,2)) / (2*b*c)
    sinA = math.sqrt(1 - pow(cosA,2))
    R = a / (2 * sinA)
    cen = simul_eq(x2-x1, y2-y1, (y2**2 - y1**2 + x2**2 - x1**2) / 2, x3-x1, y3-y1, (y3**2 - y1**2 + x3**2 - x1**2) / 2)
    print(' '.join(cen), '{0:.3f}'.format(R))