思路:就是使用二维前缀和的模板:

先放模板:

#include<iostream>
using namespace std;
#define ll long long
const int maxn = 1e3 + ;
ll a[maxn][maxn], jx[maxn][maxn];
ll n, m, L, xa, ya, xb, yb;
ll aa, bb, maxx = ;
int main(){
cin >> n >> m>>L;
for (int i = ; i <= n;++i)
for (int j = ; j <= m; ++j)
cin >> a[i][j]; for (int i = ; i <= n;++i)
for (int j = ; j <= m; ++j)
jx[i][j] = a[i][j] + jx[i - ][j] + jx[i][j - ] - jx[i - ][j - ]; for (int i = ; i <= n - L+;++i)
for (int j = ; j <= m - L+; ++j)
{
xa = i; ya = j; xb = i + L-; yb = j + L-;
ll sum = jx[xb][yb] - jx[xa-][yb] - jx[xb][ya-] + jx[xa-][ya-];
if (maxx < sum){ maxx = sum; aa = xa; bb = ya; }
}
cout << aa << " " << bb << endl;
}
05-11 11:17