Description
Inside the maze of N*n, "#" is the Wall, "." For the road, "s" for the beginning, "E" for the end, altogether 4 directions can walk. From the upper left corner ((0,0) "s" position to the lower right corner ((n-1,n-1) "E") position, you can walk the general output Yes, can not go output no.
Input
The first behavior of the input is an integer m, which indicates the number of mazes.
The first behavior of each maze data followed by an integer n (n≤16), representing the edge length of the maze, followed by n lines of n characters per line, with no spaces separating the characters.
Output
Output has m line, each line corresponding to the maze can go, then output yes, otherwise output No.
Sample Input
... E
Sample Output
YES
Exercises
#include <iostream>using namespacestd;Chara[ -][ -];BOOLvis[ -][ -];intxx[5]={0,-1,1,0,0};intyy[5]={0,0,0,-1,1};intM,n,judge;voidDfsintXinty) {Vis[x][y]=true; if(A[x][y] = ='e') {Judge=1; return; } for(intI=1; i<=4; i++) if(x+xx[i]>0&& x+xx[i]<=n && y+yy[i]>0&& y+yy[i]<=N)if(A[x+xx[i]][y+yy[i]]! ='#'&&!vis[x+xx[i]][y+Yy[i]]) DFS (x+xx[i],y+yy[i]);}intMain () {CIN>>m>>N; for(intI=1; i<=m;i++) {Judge=0; for(intj=1; j<=n;j++) for(intk=1; k<=n;k++) Cin>>A[j][k]; DFS (1,1); if(judge) cout<<"YES"; Elsecout<<"NO"; } return 0;}
"Codevs1215" Maze