This question .... The test instructions is very long. The general meaning is to give a maze, the maze has 16 of the state. Then each lattice in the maze consists of a hexadecimal number, and then converts the number to 2, clockwise around a circle to indicate whether it is possible to walk around the lattice, 0 to walk, and 1 to not go =_=
And then let you judge which of the 4 types of Maze the maze is.
Each labyrinth is guaranteed to have only one inlet and outlet. And there's only one wall between the adjacent squares.
Four kinds of mazes are like this.
① from start to finish no path exists
There are two points in the ② maze where there are no paths to pass.
There are several simple paths in the existence of two points in the maze of ③, in fact, it is to judge whether there is a ring
④ is not above
In fact, the map is not very good to build =_=
It's good to use DFS after the diagram is built.
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>using namespace STD;typedefpair<int,int>pii; vector<pii>DintN,m;intHas (intIintj) {returnI*m+j;}intGetxintx) {returnx/m;}intGetyintY) {returnY%m;}BOOLImapintXintY) {if(x>=0&&x<n&&y>=0&&Y<M)return 1;return 0;}Const intn= -;intdir[4][2] = {0,-1,1,0,0,1, -1,0};intMp[n][n];CharS[n];intVis[n][n];intVis2[n*n]; vector<int>G[n*n];intDfsintUintP) {intX=getx (U);intY=gety (U); vis[x][y]++;intM=g[u].size (); for(intI=0; i<m;i++) {intV=g[u][i];intXx=getx (v);intYy=gety (v);if(V!=p&&!vis[xx][yy]) DFS (V,U); }return 0;}intDFS1 (intUintP) {//printf ("%d\n", u); if(Vis2[u]) {return 1; } vis2[u]=1;intM=g[u].size (); for(intI=0; i<m;i++) {intV=g[u][i];if(v!=p)if(DFS1 (V,u))return 1; }return 0;}intMain () { while(~scanf("%d%d", &n, &m), n+m) {memset(Vis,0,sizeof(VIS));memset(Vis2,0,sizeof(VIS2)); D.clear (); for(inti =0; I < n; i++) {scanf('%s ', s); for(intj =0; J < M; J + +) {G[has (i,j)].clear ();if(' 0 '<= S[j] && s[j]<=' 9 ') Mp[i][j] = s[j]-' 0 ';ElseMP[I][J] = s[j]-' A '+Ten; } } for(inti =0; I < n; i++) for(intj =0; J < M; J + +) for(intK =0; K <4; k++) {intx = i+dir[k][0], y = j+dir[k][1];if(!imap (x, y)) {if((mp[i][j]& (1<<k)) = =0) {D.push_back (PII (i,j));//printf ("%d%d%d\n", i,j,1<<k);}Continue; }if((mp[i][j]& (1<<k)) = =0) {G[has (I,J)].push_back (has (x, y)); }} sort (D.begin (), D.end ()); DFS (Has (d[0].first,d[0].second),-1);if(vis[d[1].first][d[1].second]==0) {printf("NO solution\n");Continue; }intflag=0; for(intI=0; i<n;i++) { for(intj=0; j<m;j++)if(vis[i][j]==0) {flag=1; Break; } }if(flag) {printf("Unreachable cell\n");Continue; }intFlag2=0;memset(Vis,0,sizeof(VIS)); FLAG2=DFS1 (0,-1);//printf ("%d\n", Flag2); if(FLAG2)printf("Multiple paths\n");Else printf("MAZE ok\n"); }return 0; }
CSU 1566The Maze Makers