CCFCSP试题编号:202104-2试题名称:邻域均值

CCFCSP试题编号:202104-2试题名称:邻域均值_第1张图片

#include 
using namespace std;
int A[605][605];
int ans = 0;
int acc[605][605];
int main()
{
    int n, L, r, t;
    cin >> n >> L >> r >> t;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            cin >> A[i][j];
            acc[i][j] = acc[i - 1][j] + acc[i][j - 1] - acc[i - 1][j - 1] + A[i][j];
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            int left = max(j - r, 1);
            int right = min(j + r, n);
            int upper = max(i - r, 1);
            int down = min(i + r, n);
            int near = acc[down][right] - acc[down][left - 1] - acc[upper - 1][right] + acc[upper - 1][left - 1];
            if (near <= (down - upper + 1) * (right - left + 1) * t) ans++;
        }
    }
    cout << ans << endl;
}

 

你可能感兴趣的:(ccf-csp练习题题解,算法学习,均值算法,算法)