bool visit[maxn];///访问标记 const int dr[]= {-1,0,1,0,-1,1,-1,1}; ///向左上右下,左下,右上,右下,左上 const int dc[]= {0,1,0,-1,-1,1,1,-1}; struct node { int r; int c; int step; }; node input[maxn]; void bfs(node start) { queue <node> q; /// BFS 队列 node now,next; /// 定义2 个状态,当前和下一个 start.Step_Counter=0; /// 计数器清零 q.push(start); /// 入队 visit[start.x][start.y]=1; /// 访问标记 while(!q.empty()) { now=q.front(); q.pop(); if(符合输出条件) { 输出操作; return; } for(int i=0; i<8; i++) { next.r=now.r+dr[i],next.c=now.c+dc[i]; next.step=now.step+1; if(符合前进条件) { visit[next.r][next.c]=1; q.push(next); } } } return; }
浙公网安备 33010602011771号