http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=23222
這題使用公式解 2A分之負B正負根號b平方減4AC 就能求出xy解
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
while (n-- != 0) {
int a = scn.nextInt(), b = scn.nextInt(), c = scn.nextInt(), d = scn.nextInt(), n1 = 0, n2 = 0;
n1 = -(a + d);
n2 = (a * d - c * c);
double x = (-n1 + Math.pow(n1 * n1 - 4 * n2, 0.5)) / 2.0, y = (-n1 - Math.pow(n1 * n1 - 4 * n2, 0.5)) / 2.0;
System.out.printf("%.2f %.2f\n", x > y ? x : y, x > y ? y : x);
}
}
/*
題目:[Problem B1-易] Eigenvalues of a 2x2 Matrix
作者:1010
時間:西元 2016 年 8 月 */
}