In the maze, X is used as the wall, spaces are passed, and * the start point is marked. Then you need to brush the wall now to find the connected blocks that can be reached by the starting point of the room. In this topic, the wall is a printable character except a few characters, not X. The question is treated as X, and the result is ac ~ It seems that the wall is 3 grids wide and 1 grid thick ~
Train of Thought: Find the start point and write it down, and then perform a deep search from the start point.
Note: When the sample data is copied from the website to the TXT file, many spaces are automatically removed, causing the test data to not match the meaning of the question. (It is not easy to find that many spaces are missing in the copy and paste process ~) In this case, if it is the if statement commented out by DFX in my code, the program will crash. (The reason is that I used a null character to initialize maze before initialization, and some space characters in the modified test data lead to null characters above the characters ~)
Here, the character X is used to initialize the maze. Since X is used as the wall to close the entire Maze, it is no longer necessary to circle X around the maze peripheral as in the previous questions to avoid judging whether the coordinates are out of bounds. You do not need to determine whether the coordinates are out of bounds.
It's not hard, but it's been a long time since the crash was triggered. I didn't expect a problem with copying sample data ~
Code:
// # Define local # include <stdio. h> # include <string. h> # define maxh 35 # define maxl 90 void DFS (int x, int y); char maze [maxh] [maxl]; // int visit [maxh] [maxl]; int dir [] [4] = {-,}, {,-}; // lrudint main () {# ifdef local freopen ("784.in ", "r", stdin); freopen ("784.out"," W ", stdout); # endif int N; scanf (" % d ", & N); getchar (); while (n --> 0) {memset (maze, 'x', sizeof (maze); char s [maxl]; int h = 0; int SX = 0, sy = 0; While (gets (s) & S [0]! = '_') // It is an underscore _ not a short line-{// printf ("% s \ n", S); int Len = strlen (s ); for (INT I = 0; I <= Len; ++ I) // less than or equal to Len, assign the final \ 0 to the final {maze [H] [I] = s [I]; If (maze [H] [I] = '*') {SX = H; Sy = I ;}} H ++;} strcpy (maze [H ++], S); DFS (sx, Sy ); for (INT I = 0; I
Exploration of the MVP 784 maze