Home > Back-end >  Stack maze have great spirit ah
Stack maze have great spirit ah

Time:11-03

Not found in the book, but also look not to understand, and a great spirit to write down the code

CodePudding user response:

Fyi:
/* * 
* @ the expand of Title mice mazes to explore
* @ Author Sun Kun
* @ the Date 2013-11-16
* @ At XUST
* @ All Copyright by Sun Kun
*
*/

#include
using namespace std;

Int maze [9] [9]={//initializes the maze, maze in English as "maze"
,2,2,2,2,2,2,2,2 {2},
,0,0,0,0,0,0,0,2 {2},
,0,2,2,0,2,2,0,2 {2},
,0,2,0,0,2,0,0,2 {2},
,0,2,0,2,0,2,0,2 {2},
,0,0,0,0,0,2,0,2 {2},
,2,0,2,2,0,2,2,2 {2},
,0,0,0,0,0,0,0,2 {2},
,2,2,2,2,2,2,2,2 {2}
};

Int force=1, startJ=1;//entry ranks coordinate
Int endI=7, endJ=7;//export ranks coordinate

Void visit (int, int j)//automatic search path
{
int m,n;

As [I] [j]=1;

If ((I==endI) & amp; & (j)==endJ)
{
Cout & lt; For (m=0; M<9. M++)
{
For (n=0; N<9. N++)
{
If (maze [m] [n]==2)
Cout & lt; <"S";
Else if (maze [m] [n]==1)
Cout & lt; <"♀";
The else
Cout & lt; <"";
}
Cout & lt; }
}

If (as [I] [j + 1)==0)
Visit (I, j + 1);
If (maze [j] [I + 1]==0)
Visit (I + 1, j);
If (as [I] [1]==0)
Visit (I, j - 1);
If (maze [I - 1) [j]==0)
Visit (I - 1, j);

As [I] [j]=0;

}

Int main (void)
{
Int I, j;

Cout & lt; <"Display maze:" & lt; for(i=0; i<9. I++)
{
for(j=0; j<9. J++)
{
If (as [I] [j]==2)
Cout & lt; <"S";
The else
Cout & lt; <"";
}
Cout & lt; }

Visit (force, startJ);

return 0;
}

CodePudding user response:

reference 1/f, zhao teacher reply:
are for reference only:
/* ** @ the expand of Title mice mazes to explore 
* @ Author Sun Kun
* @ the Date 2013-11-16
* @ At XUST
* @ All Copyright by Sun Kun
*
*/

#include
using namespace std;

Int maze [9] [9]={//initializes the maze, maze in English as "maze"
,2,2,2,2,2,2,2,2 {2},
,0,0,0,0,0,0,0,2 {2},
,0,2,2,0,2,2,0,2 {2},
,0,2,0,0,2,0,0,2 {2},
,0,2,0,2,0,2,0,2 {2},
,0,0,0,0,0,2,0,2 {2},
,2,0,2,2,0,2,2,2 {2},
,0,0,0,0,0,0,0,2 {2},
,2,2,2,2,2,2,2,2 {2}
};

Int force=1, startJ=1;//entry ranks coordinate
Int endI=7, endJ=7;//export ranks coordinate

Void visit (int, int j)//automatic search path
{
int m,n;

As [I] [j]=1;

If ((I==endI) & amp; & (j)==endJ)
{
Cout & lt; For (m=0; M<9. M++)
{
For (n=0; N<9. N++)
{
If (maze [m] [n]==2)
Cout & lt; <"S";
Else if (maze [m] [n]==1)
Cout & lt; <"♀";
The else
Cout & lt; <"";
}
Cout & lt; }
}

If (as [I] [j + 1)==0)
Visit (I, j + 1);
If (maze [j] [I + 1]==0)
Visit (I + 1, j);
If (as [I] [1]==0)
Visit (I, j - 1);
If (maze [I - 1) [j]==0)
Visit (I - 1, j);

As [I] [j]=0;

}

Int main (void)
{
Int I, j;

Cout & lt; <"Display maze:" & lt; for(i=0; i<9. I++)
{
for(j=0; j<9. J++)
{
If (as [I] [j]==2)
Cout & lt; <"S";
The else
Cout & lt; <"";
}
Cout & lt; }

Visit (force, startJ);

return 0;
}

problem is the shortest path and path length
  • Related