连通块模板用法:
- 输入数据:0/1矩阵,若标准输入不是0/1矩阵,请转换。
转换0/1矩阵,你可能需要形如这样的代码:
char ch
switch(ch) {
case '墙': {
s[i][j] = 0;break;}
case '空地': {
s[i][j] = 1;break;}
}
- 适合问题:连通块
广度优先搜索版:
#include<bits/stdc++.h>
using namespace std;
struct node
{
int x;
int y;
node(){
}
node(int x1,int y1):x(x1),y(y1){
}
};
int n,m;
int u[4][2]={
{
1,0},{
-1,0},{
0,1},{
0,-1}};
int head=1;
int tail=1