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: Wrong Answer

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

n = input()
ans = []
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 = ((l2**2 + l3**2 - l1**2)*l1*x1**2 +\
          (l3**2 + l1**2 - l2**2)*l2*x2**2 +\
          (l1**2 + l2**2 - l3**2)*l3*x3**2)/(16*S**2)
    py = ((l2**2 + l3**2 - l1**2)*l1*y1**2 +\
          (l3**2 + l1**2 - l2**2)*l2*y2**2 +\
          (l1**2 + l2**2 - l3**2)*l3*y3**2)/(16*S**2)
    r = ((px-x1)**2+(py-y1)**2)**0.5
    ans.append([px,py,r])

for an in ans:
    print '%.3f %.3f %.3f ' % (an[0],an[1],an[2])

Submission status: Wrong Answer

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

n = input()
ans = []
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 = ((l2**2 + l3**2 - l1**2)*l1*x1**2 +\
          (l3**2 + l1**2 - l2**2)*l2*x2**2 +\
          (l1**2 + l2**2 - l3**2)*l3*x3**2)/(16*S**2)
    py = ((l2**2 + l3**2 - l1**2)*l1*y1**2 +\
          (l3**2 + l1**2 - l2**2)*l2*y2**2 +\
          (l1**2 + l2**2 - l3**2)*l3*y3**2)/(16*S**2)
    r = ((px-x1)**2+(py-y1)**2)**0.5
    print '%.3f %.3f %.3f ' % (px,py,r)

Submission status: Wrong Answer

Solution code:
import math
for val in xrange(0,input()):
	x = map(float,raw_input().split(' '))
	a = 2*(x[0]-x[2])
	b = 2*(x[1]-x[3])
	c = (x[1]**2-x[2]**2)-(x[1]**2-x[3]**2)
	d = 2*(x[0]-x[4])
	e = 2*(x[1]-x[5])
	f = (x[1]**2-x[4]**2)-(x[1]**2-x[5]**2)
	p = round((c*e-b*f)/(a*e-b*d),4)
	q = round((a*f-c*d)/(a*e-b*d),4)
	X = '%.3f' % p
	Y = '%.3f' % q
	if str(X) == '-0.000': X = '%.3f' % 0.000
	if str(Y) == '-0.000': Y = '%.3f' % 0.000
	r = (x[0]-float(X))**2+(x[1]-float(Y))**2
	r = math.sqrt(r)
	r = math.fabs(r)
	r = round(r,4)
	R = '%.3f' % r
	print X,Y,R

Submission status: Wrong Answer

Solution code:
import math
for val in xrange(0,input()):
	x = map(float,raw_input().split(' '))
	a = 2*(x[0]-x[2])
	b = 2*(x[1]-x[3])
	c = (x[1]**2-x[2]**2)+(x[1]**2-x[3]**2)
	d = 2*(x[0]-x[4])
	e = 2*(x[1]-x[5])
	f = (x[1]**2-x[4]**2)+(x[1]**2-x[5]**2)
	p = round((c*e-b*f)/(a*e-b*d),4)
	q = round((a*f-c*d)/(a*e-b*d),4)
	X = '%.3f' % p
	Y = '%.3f' % q
	if str(X) == '-0.000': X = '%.3f' % 0.000
	if str(Y) == '-0.000': Y = '%.3f' % 0.000
	r = (x[0]-float(X))**2+(x[1]-float(Y))**2
	r = math.sqrt(r)
	r = math.fabs(r)
	r = round(r,4)
	R = '%.3f' % r
	print X,Y,R

Submission status: Wrong Answer

Solution code:
import math
import decimal
for val in xrange(0,input()):
	x = map(float,raw_input().split(' '))


	a = decimal.Decimal(2*(x[0]-x[2]))
	b = decimal.Decimal(2*(x[1]-x[3]))
	c = decimal.Decimal((x[1]**2-x[2]**2)+(x[1]**2-x[3]**2))
	d = decimal.Decimal(2*(x[0]-x[4]))
	e = decimal.Decimal(2*(x[1]-x[5]))
	f = decimal.Decimal((x[1]**2-x[4]**2)+(x[1]**2-x[5]**2))
	p = decimal.Decimal(round((c*e-b*f)/(a*e-b*d),4))
	q = decimal.Decimal(round((a*f-c*d)/(a*e-b*d),4))
	X = '%.3f' % p
	Y = '%.3f' % q
	if str(X) == '-0.000': X = '%.3f' % 0.000
	if str(Y) == '-0.000': Y = '%.3f' % 0.000
	r = decimal.Decimal((x[0]-float(X))**2+(x[1]-float(Y))**2)
	r = math.sqrt(r)
	r = math.fabs(r)
	r = round(r,4)
	R = '%.3f' % r
	print X,Y,R

Submission status: Wrong Answer

Solution code:

import sys
import math


def solv(x1, y1, x2, y2, x3, y3):
    if y2 == y1:
        xp = 0.5 * (x1 + x2)
        yp = (x3 - x1)/(y3 - y1) * xp + 0.5 * (y1 + y3 - (x3**2 - x1**2)/(y3 - y1))
    elif y3 == y1:
        xp = 0.5 * (x1 + x3)
        yp = (x2 - x1)/(y2 - y1) * xp + 0.5 * (y1 + y2 - (x2**2 - x1**2)/(y2 - y1))
    else:
        xp = 0.5 * (y3 - y2 - (x3**2 - x1**2)/(y3 - y1) + (x2**2 - x1**2)/(y2 - y1))/((x2 - x1)/(y2 - y1) - (x3 - x1)/(y3 - y1))
        yp = (x2 - x1)/(y2 - y1) * xp + 0.5 * (y1 + y2 - (x2**2 - x1**2)/(y2 - y1))
    r = math.sqrt((x1 - xp)**2 + (y1 - yp)**2)
    return (xp, yp, r)



#input_file = open(sys.argv[1], "r")
#lines = input_file.readlines()
lines = sys.stdin.readlines()
lines.pop(0)

for line in lines:
    l = map((lambda x: float(x)), line.split(' '))
    x1 = l[0]
    y1 = l[1]
    x2 = l[2]
    y2 = l[3]
    x3 = l[4]
    y3 = l[5]
    xp, yp, r = solv(x1, y1, x2, y2, x3, y3)
    print("%5.3f %5.3f %5.3f" % (xp, yp, r))

Submission status: Wrong Answer

Solution code:

import sys
import math


def solv(x1, y1, x2, y2, x3, y3):
    if y2 == y1:
        xp = 0.5 * (x1 + x2)
        yp = (x3 - x1)/(y3 - y1) * xp + 0.5 * (y1 + y3 - (x3**2 - x1**2)/(y3 - y1))
    elif y3 == y1:
        xp = 0.5 * (x1 + x3)
        yp = (x2 - x1)/(y2 - y1) * xp + 0.5 * (y1 + y2 - (x2**2 - x1**2)/(y2 - y1))
    else:
        xp = 0.5 * (y3 - y2 - (x3**2 - x1**2)/(y3 - y1) + (x2**2 - x1**2)/(y2 - y1))/((x2 - x1)/(y2 - y1) - (x3 - x1)/(y3 - y1))
        yp = (x2 - x1)/(y2 - y1) * xp + 0.5 * (y1 + y2 - (x2**2 - x1**2)/(y2 - y1))
    r = math.sqrt((x1 - xp)**2 + (y1 - yp)**2)
    return (xp, yp, r)



#input_file = open(sys.argv[1], "r")
#lines = input_file.readlines()
lines = sys.stdin.readlines()
lines.pop(0)

for line in lines:
    l = map((lambda x: float(x)), line.split(' '))
    x1 = l[0]
    y1 = l[1]
    x2 = l[2]
    y2 = l[3]
    x3 = l[4]
    y3 = l[5]
    xp, yp, r = solv(x1, y1, x2, y2, x3, y3)
    print("%5.3f %5.3f %5.3f" % (round(xp, 3), round(yp, 3), round(r, 3)))

Submission status: Wrong Answer

Solution code:

import sys
import math


def solv(x1, y1, x2, y2, x3, y3):
    if y2 == y1:
        xp = 0.5 * (x1 + x2)
        yp = (x3 - x1)/(y3 - y1) * xp + 0.5 * (y1 + y3 - (x3**2 - x1**2)/(y3 - y1))
    elif y3 == y1:
        xp = 0.5 * (x1 + x3)
        yp = (x2 - x1)/(y2 - y1) * xp + 0.5 * (y1 + y2 - (x2**2 - x1**2)/(y2 - y1))
    elif y3 == y2:
        xp = 0.5 * (x2 + x3)
        yp = (x2 - x2)/(y1 - y2) * xp + 0.5 * (y2 + y1 - (x1**2 - x2**2)/(y1 - y2))
    else:
        xp = 0.5 * (y3 - y2 - (x3**2 - x1**2)/(y3 - y1) + (x2**2 - x1**2)/(y2 - y1))/((x2 - x1)/(y2 - y1) - (x3 - x1)/(y3 - y1))
        yp = (x2 - x1)/(y2 - y1) * xp + 0.5 * (y1 + y2 - (x2**2 - x1**2)/(y2 - y1))
    r = math.sqrt((x1 - xp)**2 + (y1 - yp)**2)
    return (xp, yp, r)



#input_file = open(sys.argv[1], "r")
#lines = input_file.readlines()
lines = sys.stdin.readlines()
lines.pop(0)

for line in lines:
    l = map(float, line.split(' '))
    x1 = l[0]
    y1 = l[1]
    x2 = l[2]
    y2 = l[3]
    x3 = l[4]
    y3 = l[5]
    xp, yp, r = solv(x1, y1, x2, y2, x3, y3)
    print("%5.3f %5.3f %5.3f" % (round(xp, 3), round(yp, 3), round(r, 3)))

Submission status: Wrong Answer

Solution code:
import math


class Triangle:
    def __init__(self, x1, y1, x2, y2, x3, y3):
        self.x1 = x1
        self.x2 = x2
        self.x3 = x3
        self.y1 = y1
        self.y2 = y2
        self.y3 = y3
        self.c = math.hypot(x1 - x2, y1 - y2)
        self.a = math.hypot(x2 - x3, y2 - y3)
        self.b = math.hypot(x3 - x1, y3 - y1)
        print self.a
        print self.b
        print self.c
        self.degreeA = math.acos((self.b ** 2 + self.c ** 2 - self.a ** 2) / (2 * self.b * self.c))
        self.degreeB = math.acos((self.c ** 2 + self.a ** 2 - self.b ** 2) / (2 * self.c * self.a))
        self.degreeC = math.acos((self.a ** 2 + self.b ** 2 - self.c ** 2) / (2 * self.a * self.b))

    def circumscribedCircleRadius(self):
        return self.a / math.sin(self.degreeA) / 2.0

    def circumscribedCircleX(self):
        A = math.sin(2.0 * self.degreeA)
        B = math.sin(2.0 * self.degreeB)
        C = math.sin(2.0 * self.degreeC)
        return (self.x1 * A + self.x2 * B + self.x3 * C) / (A + B + C)

n = input()
for t in range(n):
    data = map(float, raw_input().split())
    t = Triangle(data[0], data[1], data[2], data[3], data[4], data[5])
    print "%.3f %.3f" % (round(t.circumscribedCircleRadius(),4), round(t.circumscribedCircleRadius(), 4))

Submission status: Wrong Answer

Solution code:
import math


class Triangle:
    def __init__(self, x1, y1, x2, y2, x3, y3):
        self.x1 = x1
        self.x2 = x2
        self.x3 = x3
        self.y1 = y1
        self.y2 = y2
        self.y3 = y3
        self.c = math.hypot(x1 - x2, y1 - y2)
        self.a = math.hypot(x2 - x3, y2 - y3)
        self.b = math.hypot(x3 - x1, y3 - y1)
        print self.a
        print self.b
        print self.c
        self.degreeA = math.acos((self.b ** 2 + self.c ** 2 - self.a ** 2) / (2 * self.b * self.c))
        self.degreeB = math.acos((self.c ** 2 + self.a ** 2 - self.b ** 2) / (2 * self.c * self.a))
        self.degreeC = math.acos((self.a ** 2 + self.b ** 2 - self.c ** 2) / (2 * self.a * self.b))

    def circumscribedCircleRadius(self):
        return self.a / math.sin(self.degreeA) / 2.0

    def circumscribedCircleX(self):
        A = math.sin(2.0 * self.degreeA)
        B = math.sin(2.0 * self.degreeB)
        C = math.sin(2.0 * self.degreeC)
        return (self.x1 * A + self.x2 * B + self.x3 * C) / (A + B + C)

    def circumscribedCircleY(self):
        A = math.sin(2.0 * self.degreeA)
        B = math.sin(2.0 * self.degreeB)
        C = math.sin(2.0 * self.degreeC)
        return (self.y1 * A + self.y2 * B + self.y3 * C) / (A + B + C)
    
n = input()
for t in range(n):
    data = map(float, raw_input().split())
    t = Triangle(data[0], data[1], data[2], data[3], data[4], data[5])
    print "%.3f %.3f %.3f" % (round(t.circumscribedCircleX(),4),
                         round(t.circumscribedCircleY(),4),
                         round(t.circumscribedCircleRadius(), 4))

Submission status: Wrong Answer

Solution code:
import math


class Triangle:
    def __init__(self, x1, y1, x2, y2, x3, y3):
        self.x1 = x1
        self.x2 = x2
        self.x3 = x3
        self.y1 = y1
        self.y2 = y2
        self.y3 = y3
        self.c = math.hypot(x1 - x2, y1 - y2)
        self.a = math.hypot(x2 - x3, y2 - y3)
        self.b = math.hypot(x3 - x1, y3 - y1)
        self.degreeA = math.acos((self.b ** 2 + self.c ** 2 - self.a ** 2) / (2 * self.b * self.c))
        self.degreeB = math.acos((self.c ** 2 + self.a ** 2 - self.b ** 2) / (2 * self.c * self.a))
        self.degreeC = math.acos((self.a ** 2 + self.b ** 2 - self.c ** 2) / (2 * self.a * self.b))

    def circumscribedCircleRadius(self):
        return self.a / math.sin(self.degreeA) / 2.0

    def circumscribedCircleX(self):
        A = math.sin(2.0 * self.degreeA)
        B = math.sin(2.0 * self.degreeB)
        C = math.sin(2.0 * self.degreeC)
        return (self.x1 * A + self.x2 * B + self.x3 * C) / (A + B + C)

    def circumscribedCircleY(self):
        A = math.sin(2.0 * self.degreeA)
        B = math.sin(2.0 * self.degreeB)
        C = math.sin(2.0 * self.degreeC)
        return (self.y1 * A + self.y2 * B + self.y3 * C) / (A + B + C)

n = input()
for t in range(n):
    data = map(float, raw_input().split())
    t = Triangle(data[0], data[1], data[2], data[3], data[4], data[5])
    print "%.3f %.3f %.3f" % (round(t.circumscribedCircleX(),4),
                         round(t.circumscribedCircleY(),4),
                         round(t.circumscribedCircleRadius(), 4))

Submission status: Wrong Answer

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

def f003():
    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
    return x0,y0,r

x0,y0,r = f003()
print "%.3f %.3f %.3f" %(x0, y0, r)

Submission status: Wrong Answer

Solution code:
import math
while True:
    try:
        x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
        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
        ss = math.sqrt(s*(s-a)*(s-b)*(s-c))
        sina = 2*ss/b/c
        sinb = 2*ss/a/c
        sinc = 2*ss/a/b
     
        r = a/sina/2
    
        a = a*a
        b = b*b
        c = c*c
        px = (a*(b+c-a)*x3 + b*(a+c-b)*x2+c*(a+b-c)*x1)/16/ss**2
        py =(a*(b+c-a)*y3 + b*(a+c-b)*y2+c*(a+b-c)*y1)/16/ss**2
    
        print "%.3f %.3f %.3f" % (px, py, r)
    except:
        break

Submission status: Wrong Answer

Solution code:
import math

def get_center(x1, y1, x2, y2, x3, y3):
  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 - y2**2
  x = (b1*c2 -b2*c1)/(a1*b2 - a2*b1)
  y = (c1*a2 -c2*a1)/(a1*b2 - a2*b1)
  return x, y

def get_length(x1, y1, x2, y2, x3, y3):
  a = math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2))
  b = math.sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3))
  c = math.sqrt((x3 - x1)*(x3 - x1) + (y3 - y1)*(y3 - y1))
  return a, b, c

def get_radius(x1, y1, x2, y2, x3, y3):
  a, b, c = get_length(x1, y1, x2, y2, x3, y3)
  s = (a + b + c)/2.0
  area = math.sqrt(s*(s-a)*(s-b)*(s-c))
  return (a*b*c)/(4.0*area)



n = int(raw_input())
for i in range(0, n):
  x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
  r = get_radius(x1, y1, x2, y2, x3, y3)
  cx, cy = get_center(x1, y1, x2, y2, x3, y3)
  print '%.3f %.3f %.3f'%(cx, cy, r)

Submission status: Wrong Answer

Solution code:
import math

def get_center(x1, y1, x2, y2, x3, y3):
  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 - y2**2
  x = (b1*c2 -b2*c1)/(a1*b2 - a2*b1)
  y = (c1*a2 -c2*a1)/(a1*b2 - a2*b1)
  return x, y

def get_length(x1, y1, x2, y2, x3, y3):
  a = math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2))
  b = math.sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3))
  c = math.sqrt((x3 - x1)*(x3 - x1) + (y3 - y1)*(y3 - y1))
  return a, b, c

def get_radius(x1, y1, x2, y2, x3, y3):
  a, b, c = get_length(x1, y1, x2, y2, x3, y3)
  s = (a + b + c)/2.0
  area = math.sqrt(s*(s-a)*(s-b)*(s-c))
  return (a*b*c)/(4.0*area)

n = int(raw_input())
for i in range(0, n):
  x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
  r = get_radius(x1, y1, x2, y2, x3, y3)
  cx, cy = get_center(x1, y1, x2, y2, x3, y3)
  print '%.3f %.3f %.3f'%(round(cx,4), round(cy, 4), round(r, 4))

Submission status: Accepted

Solution code:
import math

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

    def width(self, p):
        return math.sqrt((self.x - p.x)**2 + (self.y - p.y)**2)

    def __repr__(self):
        return '{0:.3f} {1:.3f}'.format(self.x, self.y)

def calc_cos(a,b,c):
    return (b**2 + c**2 - a**2) / (2*b*c)

def calc_sin(c):
    return math.sqrt(1 - c**2)

def calc_2sin(s,c):
    return 2 * s * c

def run():
    n = int(input())
    for _ in range(n):
        x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
        p1, p2, p3 = P(x1, y1), P(x2, y2), P(x3, y3)
        a, b, c = p1.width(p2), p2.width(p3), p3.width(p1)
        cosA, cosB, cosC = calc_cos(a,b,c), calc_cos(b,c,a), calc_cos(c,a,b)
        sinA, sinB, sinC = calc_sin(cosA), calc_sin(cosB), calc_sin(cosC)
        sin2A, sin2B, sin2C = calc_2sin(sinA, cosA), calc_2sin(sinB, cosB), calc_2sin(sinC, cosC)

        r = a / sinA / 2

        x = (p1.x * sin2B + p2.x * sin2C + p3.x * sin2A) / (sin2A + sin2B + sin2C)
        y = (p1.y * sin2B + p2.y * sin2C + p3.y * sin2A) / (sin2A + sin2B + sin2C)

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

if __name__ == '__main__':
    run()

Submission status: Accepted

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

import cmath

class Point(object):
    def __init__(self, x, y):
        self.point = complex(x, y)
    def __str__(self):
        return "x = {0}, y = {1}".format(self.point.real, self.point.imag)

class Triangle(Point):
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c
        # ３辺の長さ
        self.edgeA = abs(b.point-c.point)
        self.edgeB = abs(c.point-a.point)
        self.edgeC = abs(a.point-b.point)
        # ３角の大きさ
        self.angleA = Triangle.angle(self.edgeA, self.edgeB, self.edgeC)
        self.angleB = Triangle.angle(self.edgeB, self.edgeC, self.edgeA)
        self.angleC = Triangle.angle(self.edgeC, self.edgeA, self.edgeB)

    # 角度を求める
    def angle(A, B, C):
        return cmath.acos( (B*B+C*C-A*A)/(2*B*C) )


    # 外接円の半径
    def circumscribedCircleRadius(self):
        return abs((self.edgeA/cmath.sin(self.angleA))/2)

    # 外心
    def circumscribedCircleCenter(self):
        A = cmath.sin(2*self.angleA)
        B = cmath.sin(2*self.angleB)
        C = cmath.sin(2*self.angleC)
        X = (self.a.point.real*A + self.b.point.real*B + self.c.point.real*C) / (A+B+C)
        Y = (self.a.point.imag*A + self.b.point.imag*B + self.c.point.imag*C) / (A+B+C)
        return complex(X, Y)

n = int(input())
for i in range(n):
    line = list(map(float, input().split()))
    p1 = Point(line[0], line[1])
    p2 = Point(line[2], line[3])
    p3 = Point(line[4], line[5])
    T = Triangle(p1, p2, p3)
    center = T.circumscribedCircleCenter()
    print("{0:.3f} {1:.3f} {2:.3f}".format(center.real, center.imag, T.circumscribedCircleRadius()))

Submission status: Accepted

Solution code:
import math
n = input()
for i in range(n):
    p = map(float, raw_input().split())
    x1, y1, x2, y2, x3, y3 = p[0], p[1], p[2], p[3], p[4], p[5]
    
    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 = math.sqrt((x1 - px)**2 + (y1 - py)**2)
    print("%.3f %.3f %.3f" % (px, py, r))

Submission status: Accepted

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

import sys

def calc_det(lis):
  return lis[0]*lis[3]-lis[1]*lis[2]

def sq(x):
  return x*x

for s in sys.stdin:
  d = map(float, s.split() )
  if len(d) == 1:
    continue
  x1,y1,x2,y2,x3,y3 = d[0],d[1],d[2],d[3],d[4],d[5]
  d11 = 2*(x3-x2)
  d12 = 2*(y3-y2)
  d21 = 2*(x2-x1)
  d22 = 2*(y2-y1)
  x11 = sq(x3)-sq(x2)+sq(y3)-sq(y2)
  x21 = sq(x2)-sq(x1)+sq(y2)-sq(y1)
  y12 = x11
  y22 = x21

  x0 = calc_det( [x11,d12,x21,d22] )/calc_det( [d11,d12,d21,d22] )
  y0 = calc_det( [d11,y12,d21,y22] )/calc_det( [d11,d12,d21,d22] )

  r = ( (x0-x1)**2 + (y0-y1)**2 )**0.5

  print "%.3f %.3f %.3f" % (x0,y0,r)

'''
Bibliography
３点を通る円の半径を求む（#７）
http://www.geocities.jp/jtqsw192/FIG/313r/3point_r.htm
'''

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

def take2(iterable):
    while True:
        yield next(iterable), next(iterable)
#外積
def cross(v1, v2):
    return v1.real * v2.imag - v1.imag * v2.real
# 線分13と線分24の交点を求める
def get_intersection(p1,p2,p3,p4):
    a1 = p4 - p2
    b1 = p2 - p3
    b2 = p1 - p2
    s1 = cross(a1, b2) / 2
    s2 = cross(a1, b1) / 2
    return p1 + (p3 - p1) * s1 / (s1 + s2)

n = int(f.readline())
for i in range(n):
    p1, p2, p3 = [x + y * 1j for x, y in take2(map(float, f.readline().split()))]
    p12 = (p1 + p2) / 2
    p13 = (p1 + p3) / 2
    pxy = get_intersection(p12,p13,p12 + (p2 - p1) * 1j,p13 + (p1 - p3) * 1j)
    r = abs(pxy - p1)
    print('{:.3f} {:.3f} {:.3f}'.format(pxy.real,pxy.imag,r))

Submission status: Accepted

Solution code:
import math
for i in range(input()):
    x1,y1,x2,y2,x3,y3=map(float,raw_input().split(" "))
    if y2==y1 or y3==y1:
        if y2==y1:
            a2=-(x3-x1)/(y3-y1)
            b2=((y3+y1)-a2*(x1+x3))/2.0
            a,b,c,d,e,f=1.0,0.0,(x1+x2)/2.0,-a2,1.0,b2
        else:
            a1=-(x2-x1)/(y2-y1)
            b1=((y2+y1)-a1*(x1+x2))/2.0
            a,b,c,d,e,f=-a1,1.0,b1,1.0,0.0,(x1+x3)/2.0
    else:
        a1=-(x2-x1)/(y2-y1)
        a2=-(x3-x1)/(y3-y1)
        b1=((y2+y1)-a1*(x1+x2))/2.0
        b2=((y3+y1)-a2*(x1+x3))/2.0
        a,b,c,d,e,f=-a1,1.0,b1,-a2,1.0,b2
    py=(a*f-c*d)/(a*e-b*d)
    px=(c*e-f*b)/(a*e-b*d)
    r=math.sqrt((px-x1)**2 + (py-y1)**2)
    print "{0:.3f} {1:.3f} {2:.3f}".format(px,py,r)

Submission status: Accepted

Solution code:
# coding: utf-8
import math
for i in range(int(raw_input())):
    x1, y1, x2, y2, x3, y3 = map(float,raw_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 = math.sqrt((x1-px)**2 + (y1-py)**2)
    print "%.3f %.3f %.3f" % (px, py, r)

Submission status: Accepted

Solution code:
def calc(l):
	A1=2*(l[1][0]-l[0][0])
	B1=2*(l[1][1]-l[0][1])
	C1=l[0][0]**2-l[1][0]**2+l[0][1]**2-l[1][1]**2
	A2=2*(l[2][0]-l[0][0])
	B2=2*(l[2][1]-l[0][1])
	C2=l[0][0]**2-l[2][0]**2+l[0][1]**2-l[2][1]**2
	X=(B1*C2-B2*C1)/(A1*B2-A2*B1)
	Y=(C1*A2-C2*A1)/(A1*B2-A2*B1)
	R=((X-l[0][0])**2+(Y-l[0][1])**2)**0.5
	return tuple(map(round, [X,Y,R], [3]*3))
l=[zip(*[iter(map(float,raw_input().split()))]*2) for i in range(input())]
for ll in l:
	print "%.3f %.3f %.3f"%(calc(ll))

Submission status: Accepted

Solution code:
def calc(a,b,c,d,e,f):
	A1=2*(c-a)
	B1=2*(d-b)
	C1=a**2-c**2+b**2-d**2
	A2=2*(e-a)
	B2=2*(f-b)
	C2=a*a-e*e+b*b-f*f
	X=(B1*C2-B2*C1)/(A1*B2-A2*B1)
	Y=(C1*A2-C2*A1)/(A1*B2-A2*B1)
	R=((X-a)**2+(Y-b)**2)**0.5
	return tuple(map(round, [X,Y,R], [3]*3))
l=[map(float,raw_input().split()) for i in range(input())]
for ll in l:
	print "%.3f %.3f %.3f"%(calc(*ll))

Submission status: Accepted

Solution code:
def calc(a,b,c,d,e,f):
	A=2*(c-a)
	B=2*(d-b)
	C=a*a-c*c+b*b-d*d
	D=2*(e-a)
	E=2*(f-b)
	F=a*a-e*e+b*b-f*f
	N=(A*E-D*B)
	X=(B*F-E*C)/N
	Y=(C*D-F*A)/N
	R=((X-a)**2+(Y-b)**2)**0.5
	return tuple(map(round,[X,Y,R],[3]*3))
l=[map(float,raw_input().split())for i in range(input())]
for k in l:print"%.3f %.3f %.3f"%(calc(*k))

Submission status: Accepted

Solution code:
def calc(a,b,c,d,e,f):
	A=2*(c-a)
	B=2*(d-b)
	C=a*a-c*c+b*b-d*d
	D=2*(e-a)
	E=2*(f-b)
	F=a*a-e*e+b*b-f*f
	N=(A*E-D*B)
	X=(B*F-E*C)/N
	Y=(C*D-F*A)/N
	return tuple(map(round,[X,Y,((X-a)**2+(Y-b)**2)**0.5],[3]*3))
l=[map(float,raw_input().split())for i in range(input())]
for k in l:print"%.3f %.3f %.3f"%(calc(*k))

Submission status: Accepted

Solution code:
def g(a,b,c,d,e,f):
	A=2*(c-a)
	B=2*(d-b)
	C=a*a-c*c+b*b-d*d
	D=2*(e-a)
	E=2*(f-b)
	F=a*a-e*e+b*b-f*f
	N=(A*E-D*B)
	X=(B*F-E*C)/N
	Y=(C*D-F*A)/N
	return tuple(map(round,[X,Y,((X-a)**2+(Y-b)**2)**0.5],[3]*3))
for k in [map(float,raw_input().split())for i in range(input())]:print"%.3f %.3f %.3f"%(g(*k))

Submission status: Accepted

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

import sys
import math

n = int(input())

for data in sys.stdin:
    x1, y1, x2, y2, x3, y3 = map(float, data.split())
    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))

Submission status: Accepted

Solution code:
# coding: utf-8
#Problem Name: Circumscrived Circle of a Triangle
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

def __det(matrix):
    return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]

def __sqdist(p1,p2):
    return ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**.5

n = int(raw_input())
for i in range(n):
    x1,y1,x2,y2,x3,y3 = map(float,raw_input().split(' '))
    det = __det([[(x2-x1),(y2-y1)],[(x3-x1),(y3-y1)]])
    c1 = (x1**2-x2**2+y1**2-y2**2)/2
    c2 = (x1**2-x3**2+y1**2-y3**2)/2
    px = __det([[c1,(y1-y2)],[c2,(y1-y3)]])/det
    py = __det([[(x1-x2),c1],[(x1-x3),c2]])/det
    r = __sqdist([x1,y1],[px,py])
    print '{0:.3f} {1:.3f} {2:.3f}'.format(px,py,r)

Submission status: Accepted

Solution code:
# coding: utf-8
#Problem Name: Circumscrived Circle of a Triangle
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

def __det(matrix):
    return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]

def __sqdist(p1,p2):
    return ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**.5

n = int(raw_input())
for i in range(n):
    x1,y1,x2,y2,x3,y3 = map(float,raw_input().split(' '))
    det = __det([[(x2-x1),(y2-y1)],[(x3-x1),(y3-y1)]])
    c1 = (x2**2-x1**2+y2**2-y1**2)/2
    c2 = (x3**2-x1**2+y3**2-y1**2)/2
    px = __det([[c1,(y2-y1)],[c2,(y3-y1)]])/det
    py = __det([[(x2-x1),c1],[(x3-x1),c2]])/det
    r = __sqdist([x1,y1],[px,py])
    print '{0:.3f} {1:.3f} {2:.3f}'.format(px,py,r)

Submission status: Accepted

Solution code:
n=int(raw_input())
for i in range(n):
    x1,y1,x2,y2,x3,y3=map(float,raw_input().split())
    a=((x1-x2)**2+(y1-y2)**2)**0.5
    b=((x1-x3)**2+(y1-y3)**2)**0.5
    c=((x2-x3)**2+(y2-y3)**2)**0.5
    s=(a+b+c)/2
    ss=(s*(s-a)*(s-b)*(s-c))**0.5
    sina=2*ss/b/c
    r=a/sina/2
    a*=a
    b*=b
    c*=c
    px=(a*(b+c-a)*x3+b*(a+c-b)*x2+c*(a+b-c)*x1)/16/ss**2
    py=(a*(b+c-a)*y3+b*(a+c-b)*y2+c*(a+b-c)*y1)/16/ss**2

    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 = x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2
    a2 = y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2
    px = ((y1 - y3) * a1 - (y1 - y2) * a2) / \
        (2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3))
    py = ((x1 - x3) * a1 - (x1 - x2) * a2) / \
        (2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3))
    r = math.hypot(x1 - px, y1 - py)
    print("{0:.3f} {1:.3f} {2:.3f}".format(px, py, r))

Submission status: Accepted

Solution code:
N = int(input()) #num of test case
for i in range(N):
    #one test case
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    #vertices
    a = complex(x1, y1)
    b = complex(x2, y2)
    c = complex(x3, y3)
    #make c = 0 by parallel transformation
    a -= c
    b -= c
    
    z0 = abs(a)**2 * b - abs(b)**2 * a
    z0 /= a.conjugate() * b - a * b.conjugate()
    
    #inverse parallel transformation
    z = z0 + c
    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:
#! -*- coding:utf-8 -*-
import math
n = input()
for x in xrange(n):
    x1,y1,x2,y2,x3,y3 = map(float,raw_input().split())
    a1 = 2.0*(x2-x1)
    b1 = 2.0*(y2-y1)
    x12 = x1**2
    y12 = y1**2
    c1 = x12-x2**2+y12-y2**2
    a2 = 2.0*(x3-x1)
    b2 = 2.0*(y3-y1)
    c2 = x12-x3**2+y12-y3**2
    denom=(a1*b2-a2*b1)
    # print "x1^2 : "+str(x12)
    # print "y1^2 : "+str(y12)
    # print "a1 : "+str(a1)
    # print "b1 : "+str(b1)
    # print "c1 : "+str(c1)
    # print "a2 : "+str(a2)
    # print "b2 : "+str(b2)
    # print "c2 : "+str(c2)
    # print "denom : "+str(denom)
    x = (b1*c2-b2*c1)/denom
    y = (c1*a2-c2*a1)/denom
    r = math.sqrt((x-x1)**2+(y-y1)**2)

    print "%.3f %.3f %.3f"%(x,y,r)

Submission status: Accepted

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

    a = x2 - x1
    b = y2 - y1
    c = (x1**2 - x2**2) + (y1**2 - y2**2)

    d = x3 - x1
    e = y3 - y1
    f = (x1**2 - x3**2) + (y1**2 - y3**2)

    l = (e*c - b*f) / (a*e - b*d)
    m = (c*d - f*a) / (b*d - a*e)
    n = -(x1**2 + y1**2 + l*x1 + m*y1)

    import math
    px = round(-l/2, 3)
    py = round(-m/2, 3)
    r = round(math.sqrt(l**2 + m**2 - 4*n ) / 2, 3)
    print("{:.3f} {:.3f} {:.3f}".format(px, py, r))

Submission status: Accepted

Solution code:
def circum(x1,y1,x2,y2,x3,y3):
    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)
    R = ((x1 - X) ** 2 + (y1 - Y) ** 2) ** 0.5
    return map(lambda n: round(n,3), [X,Y,R])
N = int(input())
ans = []
for i in range(N):
    ans.append(circum(*list(map(float,input().split()))))
for i in range(N):
    print('{0:.3f} {1:.3f} {2:.3f}'.format(*ans[i]))

Submission status: Accepted

Solution code:
import sys
 
def calc_det(lis):
  return lis[0]*lis[3]-lis[1]*lis[2]
 
def sq(x):
  return x*x
 
for s in sys.stdin:
  d = map(float, s.split() )
  if len(d) == 1:
    continue
  x1,y1,x2,y2,x3,y3 = d[0],d[1],d[2],d[3],d[4],d[5]
  d11 = 2*(x3-x2)
  d12 = 2*(y3-y2)
  d21 = 2*(x2-x1)
  d22 = 2*(y2-y1)
  x11 = sq(x3)-sq(x2)+sq(y3)-sq(y2)
  x21 = sq(x2)-sq(x1)+sq(y2)-sq(y1)
  y12 = x11
  y22 = x21
 
  x0 = calc_det( [x11,d12,x21,d22] )/calc_det( [d11,d12,d21,d22] )
  y0 = calc_det( [d11,y12,d21,y22] )/calc_det( [d11,d12,d21,d22] )
 
  r = ( (x0-x1)**2 + (y0-y1)**2 )**0.5
 
  print "%.3f %.3f %.3f" % (x0,y0,r)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
 
import sys
import math
 
n = int(input())
 
for data in sys.stdin:
    x1, y1, x2, y2, x3, y3 = map(float, data.split())
    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))