× Problem 1007 初始时刻为 0

Problem 1004 把同样的c++能够ac的程序换成java,报wrong answer的错

luchy0120 | 2020-07-25 13:22:47Author
把同样的c++能够ac的程序换成java,报wrong answer的错
luchy0120 | 2020-07-25 13:30:36# 1
把同样的c++能够ac的程序换成java,报wrong answer的错
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-->0) { int n, x, y; n = sc.nextInt(); x = sc.nextInt(); y = sc.nextInt(); --x; --y; int a[][] = new int[n][n]; for (int i = 0; i < n; ++i){ for (int j = 0; j < n; ++j) { a[i][j] = sc.nextInt(); } } int ans = Integer.MAX_VALUE; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int go = (Math.abs(i - x) + Math.abs(j - y) + 1) / 2; List<Integer> v = new ArrayList<>(); for (int x0 = i - 3; x0 <= i + 3; ++x0) { for (int y0 = j - 3; y0 <= j + 3; ++y0) { if (Math.abs(i - x0) + Math.abs(j - y0) > 3) { continue; } if (x0 < 0 || x0 >= n || y0 < 0 || y0 >= n) { continue; } if (x0 != i || y0 != j) { v.add(a[x0][y0]); } } } Collections.sort(v); Collections.reverse(v); v.add(0,a[i][j]); int tt = 0, food = 0, get = v.get(0); for (int m = 1; m <= 8; ++m) { int need = Math.max(0, (8 * m * m) - food); int days = Math.max(1, (need + get - 1) / get); tt += days; food += get * days; get += v.get(m); } ans = Math.min(ans, tt + go); } } System.out.println(ans); } } }