题目

笔记

代码
import java.util.Scanner;
public class T1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int L = sc.nextInt();
int r = sc.nextInt();
int t = sc.nextInt();
int arr[][] = new int[n][n];
int sumArr[][] = new int[n+1][n+1];
for(int i = 0; i<n; i++) {
for(int j = 0; j<n; j++) {
arr[i][j] = sc.nextInt();
sumArr[i+1][j+1] = sumArr[i+1][j] + sumArr[i][j+1] - sumArr[i][j] + arr[i][j];
}
}
int res = 0;
for(int i = 1; i<= n; i++) {
for(int j = 1; j<= n; j++) {
int X1 = i-r >= 1 ? i-r : 1;
int Y1 = j-r >= 1 ? j-r : 1;
int X2 = i+r <= n ? i+r : n;
int Y2 = j+r <= n ? j+r : n;
int p = sumArr[X2][Y2] - sumArr[X2][Y1 -1] - sumArr[X1-1][Y2] + sumArr[X1-1][Y1 -1];
if(p <= (X2- X1 + 1)*(Y2 - Y1 + 1)* t) res++;
}
}
System.out.print(res);
}
}
结果