main
黄海 2 years ago
parent ab52d533f4
commit de7f48ecb7

@ -0,0 +1,27 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, c;
int a[N][N], s[N][N];
int mx = INT_MIN;
int main() {
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 x, y;
for (int i = c; i <= n; i++) // 边长为c
for (int j = c; j <= m; j++) {
if (s[i][j] - s[i - c][j] - s[i][j - c] + s[i - c][j - c] > mx) {
mx = s[i][j] + s[i - c][j - c] - s[i - c][j] - s[i][j - c];
x = i - c + 1;
y = j - c + 1;
}
}
printf("%d %d", x, y);
return 0;
}

@ -421,7 +421,37 @@ int main() {
```
#### [$P2004$ 领地选择](https://www.luogu.com.cn/problem/P2004)
二维前缀和祼题,不解释。
```cpp {.line-numbers}
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, c;
int a[N][N], s[N][N];
int mx = INT_MIN;
int main() {
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 x, y;
for (int i = c; i <= n; i++) // 边长为c
for (int j = c; j <= m; j++) {
if (s[i][j] - s[i - c][j] - s[i][j - c] + s[i - c][j - c] > mx) {
mx = s[i][j] + s[i - c][j - c] - s[i - c][j] - s[i][j - c];
x = i - c + 1;
y = j - c + 1;
}
}
printf("%d %d", x, y);
return 0;
}
```
#### [$P3397$ 地毯](https://www.luogu.com.cn/problem/P3397)
**分析**

Loading…
Cancel
Save