chentonghe @ 2024-09-01 21:29:20
#include<iostream>
using namespace std;
int a[15][15];
bool check(int x1, int y1, int x2, int y2)
{
int x[2] = {0, 0};
for (int i = x1; i <= x2; i++)
for (int j = y1; j <= y2; j++)
x[a[i][j]]++;
return x[0] == x[1];
}
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];
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 WaTleZero_pt @ 2024-09-01 21:44:06
有没有可能,输入数据是字符串不是单个的数字
by WaTleZero_pt @ 2024-09-01 21:44:21
@chentonghe
by 枫原千叶 @ 2024-09-01 21:48:57
抄的chenzhe吧,少抄点代码
int数组的读入会出问题,比如某行是“10000”,int会认为这只是一个数字,而不是五个数字
#include<iostream>
using namespace std;
int a[15][15];
char f[15][15];
bool check(int x1, int y1, int x2, int y2)
{
int x[2] = {0, 0};
for (int i = x1; i <= x2; i++)
for (int j = y1; j <= y2; j++)
x[a[i][j]]++;
return x[0] == x[1];
}
int main()
{
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> f[i][j],a[i][j]=f[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;
} @[chentonghe](/user/1391560)