二维前缀和模板啦,家人们,一眼出
pos:(up自己犯的错误,记录一下,也提醒大家)
x1<=n-c+1(+1哦·)
y1<=m-c+1
x2=x1+c-1(-1哦)
y2=y1+c-1
okk,上!
ACcode:
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int a[N][N],s[N][N],n,m,c;
void solve(){cin>>n>>m>>c;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){cin>>a[i][j];s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];}int mmax=-1<<30,x,y;for(int x1=1;x1<=n-c+1;x1++)for(int y1=1;y1<=m-c+1;y1++){int x2=x1+c-1,y2=y1+c-1;int ans=s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1];if(ans>mmax){mmax=ans;x=x1,y=y1;}}cout<<x<<" "<<y<<"\n";
}
int main() {ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);solve();return 0;
}
over~