Posted in 面试题 onJuly 10, 2016
#define MAX_SIZE 8
int H[4] = {0, 1, 0, -1};
int V[4] = {-1, 0, 1, 0};
char Maze[MAX_SIZE][MAX_SIZE] = {{‘X’,X’,X’,X’,X’,X’,X’,X’},
{‘o’,o’,o’,o’,o’,X’,X’,X’},
{‘X’,o’,X’,X’,o’,o’,o’,X’},
{‘X’,o’,X’,X’,o’,X’,X’,o’},
{‘X’,o’,X’,X’,X’,X’,X’,X’},
{‘X’,o’,X’,X’,o’,o’,o’,X’},
{‘X’,o’,o’,o’,o’,X’,o’,o’},
{‘X’,X’,X’,X’,X’,X’,X’,X’}};
void FindPath(int X, int Y) {
if(X == MAX_SIZE || Y == MAX_SIZE) {
for(int i = 0; i for(int j = 0; j printf(“%c%c”, Maze[i][j], j }else for(int k = 0; k if(X >= 0 && Y >= 0 && Y Maze[X][Y] = ‘ ‘;
FindPath(X+V[k], Y+H[k]);
Maze[X][Y] =’o;
}
}
int main(int argc, char* argv[]) {
FindPath(1,0);
}
int H[4] = {0, 1, 0, -1};
int V[4] = {-1, 0, 1, 0};
char Maze[MAX_SIZE][MAX_SIZE] = {{‘X’,X’,X’,X’,X’,X’,X’,X’},
{‘o’,o’,o’,o’,o’,X’,X’,X’},
{‘X’,o’,X’,X’,o’,o’,o’,X’},
{‘X’,o’,X’,X’,o’,X’,X’,o’},
{‘X’,o’,X’,X’,X’,X’,X’,X’},
{‘X’,o’,X’,X’,o’,o’,o’,X’},
{‘X’,o’,o’,o’,o’,X’,o’,o’},
{‘X’,X’,X’,X’,X’,X’,X’,X’}};
void FindPath(int X, int Y) {
if(X == MAX_SIZE || Y == MAX_SIZE) {
for(int i = 0; i for(int j = 0; j printf(“%c%c”, Maze[i][j], j }else for(int k = 0; k if(X >= 0 && Y >= 0 && Y Maze[X][Y] = ‘ ‘;
FindPath(X+V[k], Y+H[k]);
Maze[X][Y] =’o;
}
}
int main(int argc, char* argv[]) {
FindPath(1,0);
}
寻找迷宫的一条出路,o通路;X:障碍
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@