From 2905493de9ee7057d90d49c3c778363bab8f2d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Mon, 26 Feb 2024 13:21:03 +0800 Subject: [PATCH] 'commit' --- .../LanQiaoBei/LanQiao14STEMA20230212/8.cpp | 1 - .../LanQiaoBei/LanQiao14STEMA20230212/9.cpp | 35 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 TangDou/LanQiaoBei/LanQiao14STEMA20230212/9.cpp diff --git a/TangDou/LanQiaoBei/LanQiao14STEMA20230212/8.cpp b/TangDou/LanQiaoBei/LanQiao14STEMA20230212/8.cpp index 3ea813d..9288bc6 100644 --- a/TangDou/LanQiaoBei/LanQiao14STEMA20230212/8.cpp +++ b/TangDou/LanQiaoBei/LanQiao14STEMA20230212/8.cpp @@ -12,7 +12,6 @@ int main() { cnt += 1; else if (n % 3 == 2) cnt += 2; - cout << cnt << endl; return 0; } \ No newline at end of file diff --git a/TangDou/LanQiaoBei/LanQiao14STEMA20230212/9.cpp b/TangDou/LanQiaoBei/LanQiao14STEMA20230212/9.cpp new file mode 100644 index 0000000..5a8b39d --- /dev/null +++ b/TangDou/LanQiaoBei/LanQiao14STEMA20230212/9.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +const int N = 110; +int a[N][N], s[N][N]; +/* +4 5 +1 1 0 0 0 +1 0 1 0 0 +0 0 0 1 1 +0 0 0 1 0 +*/ +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + cin >> a[i][j]; + + // 计算二维前缀和 + 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]; + + int res = -1; + for (int x1 = 1; x1 <= n; x1++) + for (int y1 = 1; y1 <= m; y1++) + for (int x2 = x1; x2 <= n; x2++) + for (int y2 = y1; y2 <= m; y2++) { // 四层循环枚举每个矩形的左上角和右下角 + if (s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1] == 0) + res = max(res, (x2 - x1 + 1) * (y2 - y1 + 1)); + } + + cout << res << endl; + return 0; +} \ No newline at end of file