城堡问题
作者:
木可柯
,
2024-05-02 13:33:52
,
所有人可见
,
阅读 9
题号1250
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 55;
int map[N][N];
bool vis[N][N];
int n, m, cnt;
void dfs(int i, int j)
{
if(vis[i][j]) return;
/*标记当前房间*/
vis[i][j] = true;
cnt++;
/*1是西墙,2是北墙,4是东墙,8是南墙*/
if((map[i][j] & 1) == 0) dfs(i, j - 1);
if((map[i][j] & 2) == 0) dfs(i - 1, j);
if((map[i][j] & 4) == 0) dfs(i, j + 1);
if((map[i][j] & 8) == 0) dfs(i + 1, j);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> map[i][j];
int res = 0, ans = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
if(!vis[i][j]) {
cnt = 0;
ans++;
dfs(i, j);
res = max(res, cnt);
}
}
cout << ans << endl;
cout << res << endl;
return 0;
}