其他分享
首页 > 其他分享> > 202104-2 邻域均值

202104-2 邻域均值

作者:互联网

二维前缀和。

const int N = 610;
int g[N][N], sum[N][N];
int n,l,r,t;

int main()
{
    cin >> n >> l >> r >> t;
    
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        {
            cin >> g[i][j];
            sum[i][j] = sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + g[i][j];
        }
    
    int res = 0;
    for(int i = 1; i <= n; i++) 
        for(int j = 1; j <= n; j++)
        {
            int a = max(1, i - r), b = max(1, j - r);
            int c = min(n, i + r), d = min(n, j + r);
            int s = sum[c][d] - sum[c][b-1] - sum[a-1][d] + sum[a-1][b-1];
            int cnt = (c - a + 1) * (d - b + 1);
            if(s <= t * cnt) res++;
        }
        
    cout << res << endl;
    
    return 0;
}

标签:main,const,int,res,sum,均值,邻域,202104,610
来源: https://www.cnblogs.com/fxh0707/p/14907758.html