AcWing 3412. 邻域均值
原题链接
简单
作者:
飞呀
,
2021-05-04 23:12:11
,
所有人可见
,
阅读 383
前缀和,子矩阵的和
#include <iostream>
using namespace std;
const int N = 610;
int n, l, r, t ;
int matrix[N][N];
int s[N][N];
int getSum(int x1, int y1, int x2, int y2){
return s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1];
}
int main() {
cin >> n >> l >> r >> t;
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> matrix[i][j];
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + matrix[i][j];
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
int x1 = max(0, i-r);
int y1 = max(0, j-r);
int x2 = min(i+r, n-1);
int y2 = min(j+r, n-1);
int count = (x2 - x1 + 1) * (y2 - y1 + 1);
int cur = getSum(x1, y1, x2, y2);
//printf("cur = %d\n", cur);
if(cur <= t * count){
ans++;
}
}
}
printf("%d\n", ans);
return 0;
}