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: Runtime Error

Solution code:
import math
n=int(raw_input())
for i in range(n):
    x1,y1,x2,y2,x3,y3=[float(i) for i in raw_input().split()]
    t1=x1*(x2+x3-x1)+y1*(y2+y3-y1)
    t2=x2*(x1+x3-x2)+y2*(y1+y3-y2)
    t3=x3*(x1+x2-x3)+y3*(y1+y2-y3)
    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("{0} {1} {2}".format(round(px,3),round(py,3),round(r,3)))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
for i in range(n):
    x1,y1,x2,y2,x3,y3=[float(i) for i in input().split()]
    t1=x1*(x2+x3-x1)+y1*(y2+y3-y1)
    t2=x2*(x1+x3-x2)+y2*(y1+y3-y2)
    t3=x3*(x1+x2-x3)+y3*(y1+y2-y3)
    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("%f %f %f"%(round(px,3),round(py,3),round(r,3)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from numpy import *
from numpy.linalg import solve

N=input()
a1,b1,a2,b2,a3,b3=map(float, raw_input().split())

a=array([[ 2*(a2-a1),2*(b2-b1) ],[ 2*(a3-a1),2*(b3-b1) ]])
b=array([a2**2+b2**2-a1**2-b1**2,a3**2+b3**2-a1**2-b1**2])

x=solve(a, b)

print x[0],x[1],  round( ( (a1-x[0])**2+(b1-x[1])**2 )**0.5 , 3)

Submission status: Runtime Error

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


# n = int(input())
# tmp = input().split(' ')
tmp = '0.0 0.0 2.0 0.0 2.0 2.0'.split(' ')
# tmp = '0.0 3.0 -1.0 0.0 -3.0 4.0'.split(' ')
a, b, c = [(float(tmp[i]), float(tmp[i+1])) for i in range(0, len(tmp), 2)]

A = np.array(((a[0], a[1], 1),
              (b[0], b[1], 1),
              (c[0], c[1], 1)))

B = np.array((((-(a[0]**2 + a[1]**2))),
              ((-(b[0]**2 + b[1]**2))),
              ((-(c[0]**2 + c[1]**2)))))

tmp = np.dot(np.linalg.inv(A), B)

#tmp = [-6, 10, 18]

x = -tmp[0]/2
y = -tmp[1]/2
r = sqrt((tmp[0]**2 + tmp[1]**2 - 4*tmp[2])/4)

print('{:.3} {:.3} {:.3}'.format(x, y, r))

Submission status: Runtime Error

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]-X)**2+(x[1]-Y)**2
		r = math.sqrt(r)
		r = math.fabs(r)
		print X,Y,r

Submission status: Runtime Error

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]-X)**2+(x[1]-Y)**2
	r = math.sqrt(r)
	r = math.fabs(r)
	print X,Y,r

Submission status: Runtime Error

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]-X)**2+(x[1]-Y)**2
	r = math.sqrt(r)
	r = math.fabs(r)
	print X,Y,r

Submission status: Runtime Error

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)
    print "%.3f %.3f" % (round(t.circumscribedCircleRadius(),4), round(t.circumscribedCircleRadius(), 4))

Submission status: Runtime Error

Solution code:
import math

a = int(raw_input())

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

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

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

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

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

Submission status: Runtime Error

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()
    A=[]
    for i in range(n):
        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: Runtime Error

Solution code:
import math
n = int(raw_input())
for i in range(n)
    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
 
    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)

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <math.h>

int main(void){
	int n;
	double x1,y1,x2,y2,x3,y3,a,b,c,s,ss,sina,r,px,py;
	scanf("%d",&n);
	while (n--){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
		b = sqrt(pow(x1-x3,2)+pow(y1-y3,2));
		c = sqrt(pow(x2-x3,2)+pow(y2-y3,2));
		s = (a+b+c)/2;
		ss = sqrt(s*(s-a)*(s-b)*(s-c));
		sina = 2*ss/b/c;
		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/pow(ss,2);
		py = (a*(b+c-a)*y3 + b*(a+c-b)*y2+c*(a+b-c)*y1)/16/pow(ss,2);
		printf("%.3f %.3f %.3f",px, py, r);
	}
}

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <math.h>

int main(void){
	int n;
	double x1,y1,x2,y2,x3,y3,a,b,c,s,ss,sina,r,px,py;
	scanf("%d",&n);
	while (n--){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
		b = sqrt(pow(x1-x3,2)+pow(y1-y3,2));
		c = sqrt(pow(x2-x3,2)+pow(y2-y3,2));
		s = (a+b+c)/2;
		ss = sqrt(s*(s-a)*(s-b)*(s-c));
		sina = 2*ss/b/c;
		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/pow(ss,2);
		py = (a*(b+c-a)*y3 + b*(a+c-b)*y2+c*(a+b-c)*y1)/16/pow(ss,2);
		printf("%.3f %.3f %.3f\n",px, py, r);
	}
}

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <math.h>

int main(void){
	int n;
	double x1,y1,x2,y2,x3,y3,a,b,c,s,ss,sina,r,px,py;
	scanf("%d",&n);
	while (n--){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
		b = sqrt(pow(x1-x3,2)+pow(y1-y3,2));
		c = sqrt(pow(x2-x3,2)+pow(y2-y3,2));
		s = (a+b+c)/2;
		ss = sqrt(s*(s-a)*(s-b)*(s-c));
		sina = 2*ss/b/c;
		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/pow(ss,2);
		py = (a*(b+c-a)*y3 + b*(a+c-b)*y2+c*(a+b-c)*y1)/16/pow(ss,2);
		printf("%.3f %.3f %.3f\n", px, py, r);
	}
	return 0;
}

Submission status: WA: Presentation Error

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)


    print("%03.3f %03.3f %03.3f " %(p1,p2,r))

Submission status: WA: Presentation Error

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:
  x=((data[0]+data[2])*(data[0]-data[2])*(data[1]-data[5])+(data[1]+data[3])*(data[1]-data[3])*(data[1]-data[5])-(data[0]+data[4])*(data[0]-data[4])*(data[1]-data[3])-(data[1]+data[5])*(data[1]-data[5])*(data[1]-data[3]))/(2*((data[0]-data[2])*(data[1]-data[5])-(data[0]-data[4])*(data[1]-data[3])))
  y=((data[1]+data[3])*(data[1]-data[3])*(data[0]-data[4])+(data[0]+data[2])*(data[0]-data[2])*(data[0]-data[4])-(data[1]+data[5])*(data[1]-data[5])*(data[0]-data[2])-(data[0]+data[4])*(data[0]-data[4])*(data[0]-data[2]))/(2*((data[1]-data[3])*(data[0]-data[4])-(data[1]-data[5])*(data[0]-data[2])))
  r=((x-data[0])**2+(y-data[1])**2)**(1/2)
  print("{0:.3f} {1:.3f} {2:.3f}\n".format(x,y,r))

Submission status: WA: Presentation Error

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)
  print("{0:.3f} {1:.3f} {2:.3f}\n".format(x,y,r))

Submission status: WA: Presentation Error

Solution code:
n = int(input())
datasets = [0]*n
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)
  print("{0:.3f} {1:.3f} {2:.3f}\n".format(x,y,r))

Submission status: WA: Presentation Error

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}\n".format(x,y,r))

Submission status: WA: Presentation Error

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

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

    

n = input()

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