Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 659 Accepted Submission(s): 193
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { BufferedReader bu; PrintWriter pw; int n; int[][] a; public static void main(String[] args) throws IOException { new Main().work(); } void work() throws IOException { bu = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out),true); n = Integer.parseInt(bu.readLine()); while (n != 0) { a = new int[n][n]; for (int i = 0; i < n; i++) { String str[] = bu.readLine().split(" "); for (int j = 0; j < n; j++) { a[i][j] = Integer.parseInt(str[j]); } } BigInteger result = BigInteger.ZERO; int step = 0; for (int i = 0; i < n / 2; i++) {//控制圈数 BigInteger max = BigInteger.ZERO; int temp = 0; for (int j = i; j < n - 1 - i; j++) { BigInteger sum = BigInteger.ZERO; sum = sum.add(BigInteger.valueOf(a[i][j]));//第i圈的 第一行顺时针相加 sum = sum.add(BigInteger.valueOf(a[n - 1 - i][n - 1 - j]));//第i圈的最后一行逆时针相加 sum = sum.add(BigInteger.valueOf(a[j][n - 1 - i]));//第i圈的最后一列,顺时针相加 sum = sum.add(BigInteger.valueOf(a[n - 1 - j][i]));//第i圈的第一列,逆时针相加 int flag = Math.min(Math.abs(j - i),Math.abs(j - (n - 1 - i)));//每次转圈的最小步数 if (sum.compareTo(max) > 0) { max = sum; temp = flag; } else if (sum.compareTo(max) == 0 && temp > flag) { temp = flag; } } step += temp; result = result.add(max); } result = result.add(BigInteger.valueOf(a[n / 2][n / 2]));//最后再加上中心元素 pw.println(result + " " + step); n = Integer.parseInt(bu.readLine()); } } }