AcWing 3412. 邻域均值
原题链接
简单
作者:
王欢祥
,
2024-12-03 11:27:42
,
所有人可见
,
阅读 1
#include <iostream>
#include <cstring>
using namespace std;
const int N = 610;
int n, L, r, t;
int a[N][N], s[N][N];
int res = 0;
int main() {
cin >> n >> L >> r >> t;
memset(a, 0, sizeof a);
memset(s, 0, sizeof s);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
s[i][j] = s[i - 1][j] + s[i][j - 1] + a[i][j] - s[i - 1][j - 1];
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
int x1 = max(i - r, 1), y1 = max(j - r, 1);
int x2 = min(i + r, n), y2 = min(j + r, n);
int num = (x2 - x1 + 1) * (y2 - y1 + 1);
int sum = s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1];
double avg = sum * 1.0 / num;
if (avg <= t)
res++;
}
cout << res << endl;
return 0;
}