#include<iostream> #include<queue> using namespace std; char map[110][110]; int visited[110][110]; typedef struct s_e { int x,y,dir,num; }; int m,n,k; s_e start,end,now; queue<s_e>q; int d[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int BFS() { s_e temp; q.push(start);visited[start.x][start.y]=0; while(!q.empty()) { temp=q.front(); if(temp.x==end.x&&temp.y==end.y) { if(temp.num<=k) return 1;//剪枝 如果发现到终点时转弯的个数 小于k 就放回 } q.pop(); for(int i=0;i<4;i++) { s_e now; now.x=temp.x+d[i][0]; now.y=temp.y+d[i][1]; if(now.x>=1&&now.x<=m&&now.y>=1&&now.y<=n&&map[now.x][now.y]!='*') { if(temp.dir!=i)//方向不同 { now.num=temp.num+1; if(now.num>k){ goto L;}//剪枝如果发现到该点时转弯的个数 小于k 就放回 } else now.num=temp.num; now.dir=i; if(now.num<=visited[now.x][now.y]) { visited[now.x][now.y]=now.num; q.push(now); } } L:; } } return 0; } int main() { int i,j,t; cin>>t; while(t--) { cin>>m>>n; while(!q.empty()){ q.pop();}//最后一个错误没有清空 for(i=1;i<=m;i++) for(j=1;j<=n;j++) { cin>>map[i][j]; visited[i][j]=11; } cin>>k>>start.y>>start.x>>end.y>>end.x;//end 的输入要反向输入 start.dir=-1;start.num=-1; if(BFS()) cout<<"yes"<<endl; else cout<<"no"<<endl; } system("pause"); return 0; }