dhcyr @ 2024-07-29 17:47:22
B4005 [GESP202406 四级] 黑白方块```
using namespace std; int w[15][15]; bool check(int xa, int ya, int xb, int yb) { int a[2] = {0, 0}; for (int i = xa; i <= xb; i++) { for (int j = ya; j <= yb; j++) a[w[i][j]]++; } return a[0] == a[1]; } int main() { int n,m; cin>>n>>m; string a; for(int i=1;i<=n;i++) { cin>>a; for(int j=1;j<=a.size();j++) { if(a[j]=='1') { w[i][j]==1; } else { w[i][j]==0; } } } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { for (int ii = i; ii <= n; ii++) { for (int jj = j; jj <= m; jj++) { if (check(i, j, ii, jj)) ans = max(ans, (ii - i + 1) * (jj - j + 1)); } } } } cout << ans << endl; return 0; }
by dhcyr @ 2024-07-29 17:48:12
代码整理一下:
#include<bits/stdc++.h>
using namespace std;
int w[15][15];
bool check(int xa, int ya, int xb, int yb) {
int a[2] = {0, 0};
for (int i = xa; i <= xb; i++) {
for (int j = ya; j <= yb; j++)
a[w[i][j]]++;
}
return a[0] == a[1];
}
int main()
{
int n,m;
cin>>n>>m;
string a;
for(int i=1;i<=n;i++)
{
cin>>a;
for(int j=1;j<=a.size();j++)
{
if(a[j]=='1')
{
w[i][j]==1;
}
else
{
w[i][j]==0;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
for (int ii = i; ii <= n; ii++) {
for (int jj = j; jj <= m; jj++) {
if (check(i, j, ii, jj))
ans = max(ans, (ii - i + 1) * (jj - j + 1));
}
}
}
}
cout << ans << endl;
return 0;
}
by ChelseaLi @ 2024-09-03 19:07:58
我也是
by zhs0711_update @ 2024-09-04 21:16:55
注意==与=。