1 条题解
-
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000; const int MAXM = 1000; int n, m, c; int a[MAXN + 5][MAXM + 5]; int sum[MAXN + 5][MAXM + 5]; // sum[i][j] = sum(a[1][1]~a[i][j]) int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> c; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; // 预处理 sum[i][j] for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) sum[i][j] = sum[i - 1][j] + sum[i][j - 1] + (-sum[i - 1][j - 1]) + a[i][j]; // 枚举子矩形(左上角 (x,y) 右下角 (x+c-1,yy+c-1)) int ans = sum[c][c]; int ansX = 1; int ansY = 1; for (int x = 1; x + c - 1 <= n; x++) for (int y = 1; y + c - 1 <= n; y++) { int xx = x + c - 1; int yy = y + c - 1; int now = sum[xx][yy] + (-sum[xx][y - 1]) + (-sum[x - 1][yy]) + sum[x - 1][y - 1]; if (now > ans) { ans = now; ansX = x; ansY = y; } } cout << ansX << " " << ansY << "\n"; return 0; }
- 1
信息
- ID
- 1329
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 22
- 已通过
- 4
- 上传者