# Walk the Maze

Source: Internet
Author: User

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

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.