bfs()搜索,关键在于用mark[][]去标记时间
#include<stdio.h>
#include<string.h>
#include<queue>
#include<iostream>
using namespace std;
int sx,sy,ex,ey,n,m;
int mark[9][9],map[9][9],dir[4][2]={1,0,-1,0,0,1,0,-1};
struct node{
int x,y,time,step;
};
int overmap(int x,int y)
{
if(x<0||x>=n||y<0||y>=m)return 1;
else return 0;
}
int bfs()
{
memset(mark,0,sizeof(mark));//注意清零
queue<node>q;
node first,next;
first.x=sx;
first.y=sy;
first......
阅读全文