'commit'
This commit is contained in:
44
GESP/Level5/GESP202406/20240601.cpp
Normal file
44
GESP/Level5/GESP202406/20240601.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int a[N][N]; // 原始数组
|
||||
int s[N][N]; // 二维前缀和数组
|
||||
|
||||
int get(int x1, int y1, int x2, int y2) {
|
||||
return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
|
||||
}
|
||||
/*
|
||||
4 5 5
|
||||
00000
|
||||
01111
|
||||
00011
|
||||
00011
|
||||
|
||||
参考答案:6
|
||||
*/
|
||||
int main() {
|
||||
int n, m, k;
|
||||
cin >> n >> m >> k;
|
||||
char c;
|
||||
// 输入原始数组
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++)
|
||||
cin >> c, a[i][j] = c - '0';
|
||||
// 构建二维前缀和数组
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++)
|
||||
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
|
||||
|
||||
// 遍历每个可能的矩形,计算此矩形的二维前缀和,要求大于等k,求得最小的长乘以宽的值,也就是最小矩形大小
|
||||
int ans = 1e9;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++)
|
||||
for (int x = i; x <= n; x++)
|
||||
for (int y = j; y <= m; y++)
|
||||
if (get(i, j, x, y) >= k)
|
||||
ans = min(ans, (x - i + 1) * (y - j + 1));
|
||||
|
||||
if(ans==1e9) ans=0;
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user