BFS 模板
模板
void BFS(int s){
queue<int> q;
q.push(s);
while(!q.empty()){
取出队首元素top;
访问队首元素top;
将队首元素出队;
将top的下一层结点未曾入队的结点全部入队,并设置为已入队
}
}
红与黑BFS
void BFS(int x,int y ){
queue<node>q;
node start,next;
start.x=x;
start.y=y;
q.push(start);
while (!q.empty())
{
start= q.front();
q.pop();
for (int i = 0; i < 4; i++)
{
next.x = start.x+dir[i][0];
next.y = start.y+dir[i][1];
if(check(next.x,next.y)&&room[next.x][next.y]=='.'){
q.push(next);
num++;
room[next.x][next.y]='#';
}
}
}
}