社区讨论

95!!!

B4005[GESP202406 四级] 黑白方块参与者 3已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@m2gbxglq
此快照首次捕获于
2024/10/19 23:44
去年
此快照最后确认于
2025/11/04 16:46
4 个月前
查看原帖

95分求调,回复必关

CPP
#include <bits/stdc++.h>
using namespace std;

int a[11][11];

bool check(int x1, int y1, int x2, int y2)
{
	int cnt1 = 0, cnt2 = 0;
	for (int i = x1; i <= x2; i++)
	{
		for (int j = y1; j <= y2; j++)
		{
			if (a[i][j] == 1)
			{
				cnt1++;
			}
			else
			{
				cnt2++;
			}
		}
	}
	if (cnt1 == cnt2)
	{
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		string s;
		cin >> s;
		for (int j = 0; j < m; j++)
		{
			a[i][j + 1] = s[j] - '0';
		}
	}
	int ans = 0;
	for (int x1 = 1; x1 <= n; x1++)
	{
		for (int y1 = 1; y1 <= m; y1++)
		{
			for (int x2 = 1; x2 <= n; x2++)
			{
				for (int y2 = 1; y2 <= m; y2++)
				{
					if (x1 == x2 && y1 == y2)
					{
						continue;
					}
					if (check(x1, y1, x2, y2))
					{
						ans = max(ans, (x2 - x1 + 1) * (y2 - y1 + 1));
					}
				}
			}
		}
	}
	cout << ans;
	return 0;
}

回复

4 条回复,欢迎继续交流。

正在加载回复...