0 0 投票数

[ $$\displaystyle det\left(\begin{matrix}a & b \\ c & d \end{matrix}\right)=ad-bc​$$ ]

  1 2
4 3

  0.500000000

  1 1
1 0

  0.333333333

while (left < right) {
double mid = (left + right) / 2;
if (check(mid)) {
right = mid;
ans = mid;
} else {
left = mid;
}
}

check(double)是一个函数，判断在给定的值作为范数的情况下，能不能构造出一个奇异矩阵$B$，如果能，返回true，那么二分代码中就缩小右端点，否则，说明不能构造出奇异矩阵，那么右移左端点，尝试更大的范数。

import java.util.Scanner;

public class Main {

static int[] A = new int[4];

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for (int i = 0; i < A.length; i++)
A[i] = in.nextInt();
double left  =0;
double right = Integer.MAX_VALUE;
double ans = right;
double EPS = 1E-6;
while (left - right < 0 && left - right < -EPS) {
double mid = (left + right) / 2;
if (check(mid)) {
right = mid;
ans = mid;
} else {
left = mid;
}
}
System.out.println(ans);
}

private static boolean check(double mid) {
double[][] B = new double[4][2];
for (int i = 0; i < A.length; i++) {
B[i][0] = A[i] + mid;
B[i][1] = A[i] - mid;
}
double max = Integer.MIN_VALUE;
double min = Integer.MAX_VALUE;
for (int i = 0; i < 16; i++) {
int a = i / 8;
int b = i % 8 / 4;
int c = i % 4 / 2;
int d = i % 2;
double det = B[0][a] * B[3][d] - B[1][b] * B[2][c];
max = Math.max(max, det);
min = Math.min(min, det);
}
return max * min <= 0;
}

}
0 0 投票数

（可选）如果您也有个人网站，不妨分享一下

0 评论

Warning: error_log(/home/wwwroot/www.jxtxzzw.com/wp-content/plugins/spider-analyser/#log/log-0101.txt): failed to open stream: No such file or directory in /home/wwwroot/www.jxtxzzw.com/wp-content/plugins/spider-analyser/spider.class.php on line 2900