Topic:
Tenjin Elementary School time limit (normal/java) : ms/3000 MS Run memory limit: 65536 KByte
Total Submissions: 148 Tested by: 53
Title Description
"CorpseParty:blooddrive" in such a section, Banchang Zia from the United States to get six ghost door spar, led to Nirvana, the collapse of the small, relying on the power of the lucky son to escape the day small. (The story doesn't matter)
Now we're assuming there's no luck, the monitor needs to escape from Tenjin Elementary School by his own strength. Tenjin Primary School can be regarded as a two-dimensional maze, every second can only go from the current position to the top and bottom of the four adjacent lattice, because the day is small has been collapsing, so there are many points is unable to walk. Asked the monitor can be in the days of a complete collapse, that is, T seconds to escape from the Tenjin Elementary School.
Input
The first line is an integer T, which indicates the number of data groups
3 integer m t
Next, enter n rows with a string of length m for each row .
One of the characters '. ' means to pass
The character '*' indicates an impassable
The character 'O' represents the exit
The character 'X' indicates the starting position of the monitor.
Output
If you can escape the output "Happy end"
Otherwise the output "bad end"
Sample input
2
5 5 13
.....
.***.
. *x*o
.*.*.
...*.
5 5 14
.....
.***.
. *x*o
.*.*.
...*.
Sample output
Bad End
Happy End
Source of the topic
Kojimai
Topic Analysis:
Search questions. The following code can be AC, but I do not know whether the correct understanding of the author's meaning, the following code is for reference only. Use DFS to do it.
The code is as follows:
/* * a.cpp * * Created on:2015 February 24 * author:administrator * * #include <iostream> #include <cstdio>usin G namespace Std;const int maxn = 25;char MAP[MAXN][MAXN]; Map matrix. The case for storing maps int n; Number of rows int m; Number of columns int t; Target time int x1, y1; Beginning int x2, y2; End int Dir[4][2] = {//direction matrix {1, 0}, {-1, 0}, {0, 1}, {0,-1}};/** * Determine if the next step is legitimate */bool check (int x, int y) {if (X & Lt 0 | | X >= N | | Y < 0 | | Y >= m) {//If the coordinates are out of bounds return false;//indicates the next illegal}return true; Otherwise the next legal}/** * DFS. * SI: Number of rows at current node * SJ: Number of columns for current nodes * CNT: Arrival (SI,SJ) is the time used */bool dfs (int si, int sj, int cnt) {if (si = = x2 && SJ = = y2 & ;& cnt <= t) {//If you arrive at the target point within a specified time return true;//return true}int i;for (i = 0; i < 4; ++i) {//traverse adjacent nodes of the current node int tempi = Si + dir[i][0]; Computes the coordinates of the next node int tempj = SJ + dir[i][1];if (check (tempi, TEMPJ) = = False) {//if the coordinates of the next point calculated are not valid continue;//skip this node and calculate the next node}if (MAP[TEMPI][TEMPJ]! = ' * ') {//If the current node is not a wall MAP[TEMPI][TEMPJ] = ' * ';//Jiang current node is set to wall bool flag = DFS (tempi, TEMPJ, CNT + 1);//along thisThe node searches down if (flag = = True) {//If this path is feasible to return true;//returns TRUE. Indicates that the target node can reach}//when the following code indicates that the node cannot reach the target node MAP[TEMPI][TEMPJ] = ' .‘; Get the prize current node to reset to '. ' Available status}}return false; If you cannot find a path through the above, then it has been shown that the target node cannot reach}int main () {int ttt;scanf ("%d", &ttt), while (ttt--) {scanf ("%d%d%d", &n, &m, &t); int I;int j;for (i = 0; i < n; ++i) {cin >> map[i];} int wall = 0; The number of walls used for the bag of villages for (i = 0; i < n; ++i) {for (j = 0; j < m; ++j) {if (map[i][j] = = ' X ') {//record start position x1 = I;y1 = j;} else I F (map[i][j] = = ' O ') {//The location of the record end x2 = I;y2 = j;} else if (map[i][j] = = ' * ') {//count the number of walls wall++;}}} MAP[X1][Y1] = ' * '; The award starting point is set for the wall ' x ' bool result = DFS (x1, y1, 0); Iterates through if (result = = true) from the starting point {//if resultweighttrue indicates that there is such a path as printf ("Happy end\n");} else {printf ("Bad end\n"); Otherwise indicates that there is no such path}}return 0;}
Noj Internet Race D-Topic Tenjin Elementary School