题目很好理解,怎么解决超时的问题? import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, r; int[][] img; int[][] subImg; while(sc.hasNextInt()) { n = sc.nextInt(); r = sc.nextInt(); img = new int[n][n]; subImg = new int[n-2*r][n-2*r]; if(n==0 || r==0) { break; } else { for(int i=0; i<img.length; i++) { for(int j=0; j<img.length; j++) { img[i][j] = sc.nextInt(); } } for(int i=r; i<n-r; i++) { for(int j=r; j<n-r; j++) { subImg[i-r][j-r] = findMiddle(i,j,r,img); } } for(int i=0; i<subImg.length; i++) { for(int j=0; j<subImg.length; j++) { if(j == subImg.length-1) { System.out.println(subImg[i][j]); } else { System.out.print(subImg[i][j]+" "); } } } } } } public static int findMiddle(int i, int j, int r, int[][] arr) { int[] temp = new int[(2*r+1)*(2*r+1)]; int k = 0; for(int m=i-r; m<=i+r; m++) { for(int n=j-r; n<=j+r; n++) { temp[k] = arr[m][n]; k++; } } Arrays.sort(temp); return temp[temp.length/2]; } }