Created
December 4, 2011 14:45
-
-
Save mojaie/1430360 to your computer and use it in GitHub Desktop.
AOJ:0010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.text.DecimalFormat; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scn = new Scanner(System.in); | |
int n = scn.nextInt(); | |
for (int i = 0; i < n; i++) { | |
double x1 = scn.nextDouble(); | |
double y1 = scn.nextDouble(); | |
double x2 = scn.nextDouble(); | |
double y2 = scn.nextDouble(); | |
double x3 = scn.nextDouble(); | |
double y3 = scn.nextDouble(); | |
double a = 0; | |
double b = 0; | |
double c = 0; | |
double d = 0; | |
double p = 0; | |
double q = 0; | |
if (y2 - y1 != 0) { | |
a = (x1 - x2) / (y2 - y1); | |
b = -1; | |
p = - (x2 * x2 - x1 * x1 - y1 * y1 + y2 * y2) / (2 * (y2 - y1)); | |
} else { | |
a = 1; | |
p = (x1 + x2) / 2; | |
} | |
if (y3 - y2 != 0) { | |
c = (x2 - x3) / (y3 - y2); | |
d = -1; | |
q = - (x3 * x3 - x2 * x2 - y2 * y2 + y3 * y3) / (2 * (y3 - y2)); | |
} else { | |
b = 1; | |
q = (x2 + x3) / 2; | |
} | |
double delta = a * d - b * c; | |
double x = (d * p - b * q) / delta; | |
double y = (a * q - c * p) / delta; | |
double r = Math.sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)); | |
String xstr = new DecimalFormat("##0.000").format(x); | |
String ystr = new DecimalFormat("##0.000").format(y); | |
String rstr = new DecimalFormat("##0.000").format(r); | |
System.out.println(xstr + " " + ystr + " " + rstr); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment