/*<br /> 剛開始學習java 代碼寫起來總是很搓的<br /> */<br />import java.io.*;<br />import java.util.*;<br />class Node<br />{<br />int x, y, pre, count;<br />Node(int x, int y, int pre, int count)<br />{<br />this.x = x;<br />this.y = y;<br />this.pre = pre;<br />this.count = count;<br />}<br />}<br />public class Main1728<br />{<br />static int dir[][] = {{-1, 0}, {1, 0}, {0,1}, {0,-1}};<br />static char map[][] = new char[105][105];<br />static boolean hash[][] = new boolean[105][105];<br />static int n, m, k;<br />static PrintWriter cout = new PrintWriter (new OutputStreamWriter(System.out));</p><p>static boolean index(Node now)<br />{<br />if(now.x >= 0 && now.x < n && now.y >= 0 && now.y < m && now.count <= k && map[now.x][now.y] != '*')<br />return true;<br />return false;<br />}<br />static void BFS(int x1, int y1, int x2, int y2)<br />{<br />if(x1 == x2 && y1 == y2)<br />{<br />cout.println("yes");<br />cout.flush();<br />return;<br />}<br />for(int i = 0; i <= n; i++)<br />for(int j = 0; j <= m; j++)<br />hash[i][j] = false;<br />Queue <Node> Q = new LinkedList<Node>();<br />Q.clear();<br />hash[x1][y1] = true;<br />for(int i = 0; i < 4; i++)<br />{<br />int tx = x1 + dir[i][0];<br />int ty = y1 + dir[i][1];<br />int tp = i;<br />int tc = 0;<br />Node next = new Node(tx, ty, tp, tc);<br />if(!index(next))<br />continue;<br />if(!hash[tx][ty])<br />{<br />//cout.println(next.x + " 111 " + next.y + " " + next.count + " " + next.pre);<br />Q.add(next);<br />hash[next.x][next.y] = true;<br />}<br />int xxx = x1;<br />int yyy = y1;<br />while(true)<br />{<br />tx = xxx + dir[i][0];<br />ty = yyy + dir[i][1];<br />tp = i;<br />tc = 0;<br />Node nex = new Node(tx, ty, tp, tc);<br />if(index(nex))<br />{<br />if(nex.x == x2 && nex.y == y2)<br />{<br />cout.println("yes");<br />cout.flush();<br />return ;<br />}<br />//if(!hash[tx][ty])<br />{<br />Q.add(nex);<br />hash[nex.x][nex.y] = true;<br />}<br />}<br />else<br />break;<br />xxx = nex.x;<br />yyy = nex.y;</p><p>}<br />}<br />Node now = new Node(0, 0, 0, 0);<br />while(!Q.isEmpty())<br />{<br />now = Q.poll();<br />//cout.println(now.x + " 222 " + now.y + " " + now.count + " " + now.pre);<br />if(now.x == x2 && now.y == y2)<br />{<br />cout.println("yes");<br />cout.flush();<br />return ;<br />}<br />int xx = now.x;<br />int yy = now.y;<br />while(true)<br />{<br />int tx = xx + dir[now.pre][0];<br />int ty = yy + dir[now.pre][1];<br />int tp = now.pre;<br />int tc = now.count;<br />Node next = new Node(tx, ty, tp, tc);<br />if(index(next))<br />{<br />if(next.x == x2 && next.y == y2)<br />{<br />cout.println("yes");<br />cout.flush();<br />return ;<br />}<br />if(!hash[tx][ty])<br />{<br />Q.add(next);<br />hash[next.x][next.y] = true;<br />}<br />}<br />else<br />break;<br />xx = next.x;<br />yy = next.y;</p><p>}<br />for(int i = 0; i < 4; i++)<br />{<br />if(i == now.pre)<br />continue;<br />int tx = now.x + dir[i][0];<br />int ty = now.y + dir[i][1];<br />int tp = i;<br />int tc = now.count + 1;<br />Node next = new Node(tx, ty, tp, tc);<br />if(!index(next))<br />continue;<br />if(!hash[tx][ty])<br />{<br />if(next.x == x2 && next.y == y2)<br />{<br />cout.println("yes");<br />cout.flush();<br />return ;<br />}<br />Q.add(next);<br />hash[tx][ty] = true;<br />}<br />xx = next.x;<br />yy = next.y;<br />int tp1 = next.pre;<br />int tc1 = next.count;<br />while(true)<br />{<br />tx = xx + dir[tp1][0];<br />ty = yy + dir[tp1][1];<br />tp = tp1;;<br />tc = tc1;<br />Node nextt = new Node(tx, ty, tp, tc);<br />if(index(nextt))<br />{<br />if(nextt.x == x2 && nextt.y == y2)<br />{<br />cout.println("yes");<br />cout.flush();<br />return ;<br />}<br />if(!hash[tx][ty])<br />{<br />Q.add(nextt);<br />hash[nextt.x][nextt.y] = true;<br />}<br />}<br />else<br />break;<br />xx = nextt.x;<br />yy = nextt.y;</p><p>}</p><p>}<br />}<br /> cout.println("no");<br /> cout.flush();<br /> return ;</p><p>}<br />public static void main(String[] args)<br />{<br />//StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));<br />int t;<br />Scanner in = new Scanner(System.in);<br />t = in.nextInt();<br />while(t-- > 0)<br />{<br />n = in.nextInt();<br />m = in.nextInt();<br />String s = new String();<br />for(int i = 0; i < n; i++)<br />{<br />s = in.next();<br />map[i] = s.toCharArray();<br />}<br />k = in.nextInt();<br />int x1, y1, x2, y2;<br />y1 = in.nextInt();<br />y1--;<br />x1 = in.nextInt();<br />x1--;<br />y2 = in.nextInt();<br />y2--;<br />x2 = in.nextInt();<br />x2--;<br />BFS(x1, y1, x2, y2);<br />}</p><p>}<br />}<br />