AC 100的代码 import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); while(scanner.hasNext()) { int N=scanner.nextInt(); int M=scanner.nextInt(); int[][] all=new int[N][M]; for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { all[i][j]=scanner.nextInt(); } } int top=N*M; int num=0; for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { if(i>0&&all[i][j]>all[i-1][j]) { num+=all[i][j]-all[i-1][j]; } if(j>0&&all[i][j]>all[i][j-1]) { num+=all[i][j]-all[i][j-1]; } if(i<N-1&&all[i][j]>all[i+1][j]) { num+=all[i][j]-all[i+1][j]; } if(j<M-1&&all[i][j]>all[i][j+1]) { num+=all[i][j]-all[i][j+1]; } if(i==0) num+=all[i][j]; if(j==0) num+=all[i][j]; if(i==N-1) num+=all[i][j]; if(j==M-1) num+=all[i][j]; } } int result=top*2+num; System.out.println(result); } } }