Maze time: 1000ms memory limit: 10000K Total time limit: 3000ms description Determine if you can reach the exit from the entrance of the maze enter two integers to indicate the number of rows of the maze m and the number of columns n, then the coordinates of the entrance and exit, and the last M-line input maze, where 1 represents the wall, 0 indicates a space with spaces between each number. If the output can be reached, the output is "Yes", otherwise the output "No", the result occupies a row. Input Example 3 3
0 0
2 2
0 0 0
1 1 0
0 1 0 Output Example Yes
#include <iostream> using namespace std; typedef struct POSTION {int posx; int posy; } postion; static int map[25][25]; static int m,n; Static postion Startpos,endpos; static bool Flag,stop; void SearchPath (int fromdirect,int curposx,int curposy) {//cout<< "hel lo!! "<<curposx<<" "<<curposy<<endl; if (curposx==endpos.posx&&curposy==endpos.posy) {flag = true; Stop = true; cout<< "Have reached!!" <<endl; return; } if ((curposy+1<=n-1) &&map[curposx][curposy+1]==0&&fromdirect!=3&&stop==false) { SearchPath (1,curposx,curposy+1); } if ((curposx+1<=m-1) &&map[curposx+1][curposy]==0&&Amp;fromdirect!=4&&stop==false) {SearchPath (2,curposx+1,curposy); } if ((curposy-1>=0) &&map[curposx][curposy-1]==0&&fromdirect!=1&&stop==false) { SearchPath (3,curposx,curposy-1); } if ((curposx-1>=0) &&map[curposx-1][curposy]==0&&fromdirect!=2&&stop==false) { SearchPath (4,curposx-1,curposy); }} int main () {cin>>m>>n; cin>>startpos.posx>>startpos.posy; cin>>endpos.posx>>endpos.posy; for (int i = 0;i < m; i++) for (int j = 0;j < N; j + +) cin>>map[i][j]; Flag = False,stop = false; /*cout<<endl; for (int i = 0;i < m; i++) {for (int j = 0;j < N; j + +) cout<<map[i][j]<< ""; cout<<endl; } cout<<endl;*/int fromdirect = 0; int curposx = STARTPOS.POSX; int curposy = Startpos.posy; SearchPath (Fromdirect,curposx,curposy); Use Sourcedirect to mark the source direction. 1 for right, 2 for lower, 3 for left, 4 for upper if (flag==false) cout<< "No" <<endl; else cout<< "Yes" <<endl; return 0; }
Walk the Maze