文章
16
粉丝
0
获赞
54
访问
10.6k
#include <bits/stdc++.h>
using namespace std;
struct box{
bool wall[4] = {false,false,false,false}; // 代表西、北、东、南有没有墙
};
const int maxn = 55;
vector<vector<box>> mpt(maxn,vector<box>(maxn));
bool vis[maxn][maxn];
int dir[4][2] = {
{0,-1}, // 西
{-1,0}, // 北
{0,1}, // 东
{1,0} // 南
};
void dfs(int sx,int sy,int n,int m,int& cnt) // 起点坐标,地图行数、列数、房间数
{
if(!vis[sx][sy])
{
vis[sx][sy] = true;
cnt++;
}
for(int i = 0;i < 4;++i)
{
if(mpt[sx][sy].wall[i] == false) // 如果某个方向没有墙
{
int nx = sx + dir[i][0];
int ny = sy + dir[i][1];
if(nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny])
{
dfs(nx,ny,n,m,cnt);
}
}
}
}
int main()
{
memset(vis,false,sizeof(vis));
int n,m;
cin >> n >> m;
for(int i = 0;i < n;++i)
{
for(int j = 0;j < m;++j)
{
box b;
int temp;
cin >> temp;
if(temp >...
登录后发布评论
暂无评论,来抢沙发