AOJ 0101
・問題リンクCircumscribed Circle of a Triangle
・コメント
数学ができなすぎて結局ACできませんでした()
どこかで計算の誤差が生じる演算をしてしまっているのかなと・・。
とりあえず眠いので今日はここまで。
1ヶ月ぶりのコーディングでした。。。
近いうちに解きなおしたいです。。
・ソース
import java.math.BigDecimal; import java.util.Scanner; public class P0010 { static Scanner sc = new Scanner(System.in); public static void solve() { // 入力 double x1 = sc.nextDouble(); double y1 = sc.nextDouble(); double x2 = sc.nextDouble(); double y2 = sc.nextDouble(); double x3 = sc.nextDouble(); double y3 = sc.nextDouble(); calc(x1, y1, x2, y2, x3, y3); } public static void calc(double x1, double y1, double x2, double y2, double x3, double y3) { double xp = ((x1 * x1 + y1 * y1) * (y2 - y3) + (x2 * x2 + y2 * y2) * (y3 - y1) + (x3 * x3 + y3 * y3) * (y1 - y2)) / (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2; double yp = ((x1 * x1 + y1 * y1) * (x2 - x3) + (x2 * x2 + y2 * y2) * (x3 - x1) + (x3 * x3 + y3 * y3) * (x1 - x2)) / (y1 * (x2 - x3) + y2 * (x3 - x1) + y3 * (x1 - x2)) / 2; double r = ((x1 - xp) * (x1 - xp)) + ((y1 - yp) * (y1 - yp)); BigDecimal bi = new BigDecimal(String.valueOf(Math.sqrt(r))); r = bi.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue(); System.out.printf("%.3f %.3f %.3f", xp, yp, r); } public static void main(String[] args) { int count = sc.nextInt(); while (count > 0) { solve(); count--; } } }