回溯法-BFS(Breadth first search)

细胞有几个

#include
#include
#include
using namespace std;
const int N = 100+5;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
bool bz[N][N];
int num=0;
int m,n;
struct point{
	int x,y;
	point(int tx,int ty):x(tx),y(ty){}
};
void bfs(int,int);
int main(){
	cin>>m>>n;
	for(int i=0;i>ts;
		for(int j=0;j q;
	q.push(point(x,y));
	bz[x][y] = 0;
	while(!q.empty()){
		point p=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			point tp(p.x+dx[i],p.y+dy[i]);
			if(tp.x>=0&&tp.x=0&&tp.y<=n && bz[tp.x][tp.y]){
				 q.push(tp);
			 bz[tp.x][tp.y] = 0;
			}
		} 
	}
}

 

你可能感兴趣的:(回溯法-BFS(Breadth first search))