#includeusing namespace std;#define M 10#define N 10#define MaxSize 100int mg[M][N]={ { 1,1,1,1,1,1,1,1,1,1}, { 1,0,0,1,0,0,0,1,0,1}, { 1,0,0,1,0,0,0,1,0,1}, { 1,0,0,0,0,1,1,0,0,1}, { 1,0,1,1,1,0,0,0,0,1}, { 1,0,0,0,1,0,0,0,0,1}, { 1,0,1,0,0,0,1,0,0,1}, { 1,0,1,1,1,0,1,1,0,1}, { 1,1,0,0,0,0,0,0,0,1}, { 1,1,1,1,1,1,1,1,1,1}};struct{ int i; int j; int pre;}Qu[MaxSize];int front=0,rear=0;void print(int front){ while(front!=-1) { printf("a[%d][%d]\n",Qu[front].i,Qu[front].j); front=Qu[front].pre; }}void mappath(int x1,int y1,int x2,int y2){ rear++; Qu[rear].i=x1; Qu[rear].j=y1; Qu[rear].pre=-1; mg[x1][y1]=-1; int find=0; while(rear!=front) { int i,j; front++; i=Qu[front].i; j=Qu[front].j; if (i==x2&&j==y2) { find=1; print(front); } int di; for (di=0;di<3;di++) { switch(di) { case 0:i=Qu[front].i-1;j=Qu[front].j;break; case 1:i=Qu[front].i;j=Qu[front].j+1;break; case 2:i=Qu[front].i+1;j=Qu[front].j;break; case 3:i=Qu[front].i;j=Qu[front].j-1;break; } if (mg[i][j]==0) { rear++; Qu[rear].i=i;Qu[rear].j=j; Qu[rear].pre=front; mg[i][j]=-1; } } } if (!find) { printf("没路径\n"); }}int main(){ mappath(1,1,8,8);}