BFS

来源:互联网 发布:淘宝联盟推广没有图片 编辑:程序博客网 时间:2024/06/04 18:26
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};//方向向量struct node{    int x;int y;char c;int step;    }map[105][105];node Next,now;void BFS(){queue<node>s;       s.push(map[x][y]);    while(!s.empty()){        now = s.front();        s.pop();        if(now.x == X&&now.y == Y&&now.step<=K)//找到了 return掉        for(int z = 0;z<4;z++){            Next.x = dir[z][0]+now.x;            Next.y = dir[z][1]+now.y;进行各种剪枝如果都符合条件那么给这个点入队;            s.push(map[Next.x][Next.y]);            }        }}}

0 0