The Code is as follows:
# Include <stdio. h>
# Include <stdlib. h>
# Include <algorithm>
Using namespace std;
Char mass [1, 110] [2, 110]; // 1728
Int move [4] [2] = {-}, {}, {0,-1 }};
Int k, x1, y1, x2, y2;
Bool iscan;
Void dfs (int t, int x, int y, int pos) // x, y is the current coordinate, I is the subscript in the direction, t is the number of turns
{
For (int I = pos ;! Iscan; I ++)
{
Mass [x] [y] = '*';
If (mass [x + move [I % 4] [0] [y + move [I % 4] [1]! = '*')
{
If (I! = Pos) t ++;
If (t> k) return;
X = x + move [I % 4] [0];
Y = y + move [I % 4] [1];
If (x = x2 & y = y2) {iscan = true; printf ("yes \ n"); return ;}
Dfs (t, x, y, I % 4 );
Mass [x] [y] = '.';
X = x-move [I % 4] [0];
Y = y-move [I % 4] [1];
Mass [x] [y] = '.';
}
Else if (I-pos = 4)
{
Break;
}
}
}
Int main ()
{
Int n;
Scanf ("% d", & n );
While (n --)
{
Int m, n, I;
Iscan = false;
For (int I = 0; I <110; I ++) memset (mass [I], '*', 110 );
Scanf ("% d", & m, & n );
For (I = 1; I <= m; I ++)
For (int j = 1; j <= n; j ++)
Scanf ("% c", & mass [I] [j]);
Scanf ("% d", & k, & y1, & x1, & y2, & x2 );
Int pos;
For (I = 0; I <4; I ++)
If (mass [x1 + move [I % 4] [0] [y1 + move [I % 4] [1]! = '*')
{Pos = I; break ;}
Dfs (0, x1, y1, pos );
If (iscan = false) printf ("no \ n ");
}
Return 0;
}
Then I thought of a good method to use deep search + wide search, that is, the minimum number of turns in the four directions of the initial point is set to 0 (the minimum number of turns in each coordinate is set to a number larger than k ), insert these coordinates into the queue, traverse other coordinates based on the elements in the queue, find the minimum number of turns of each coordinate, and recursively know until the end point is found.