AcWing 3412. 邻域均值
原题链接
中等
作者:
luu
,
2021-04-22 17:49:11
,
所有人可见
,
阅读 408
二维前缀和
#include<iostream>
using namespace std;
int a[602][602],s[602][602];
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];
int count=0;
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] -s[i-1][j-1] +a[i][j];
//cout<<s[i][j]<<"-";
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
int res=0;
int x1=i-r,y1=j-r,x2=i+r,y2=j+r;
if(x1<=1)x1=1;
if(y1<=1)y1=1;
if(x2>n)x2=n;
if(y2>n)y2=n;
int sum=s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1];
res=(x2-x1+1)*(y2-y1+1);
double temp=sum*1.0/res;
// cout<<i<<" "<<j<<" "<<temp<<endl;
if(temp<=t)count++;
}
cout<<count;
}