1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include<bits/stdc++.h>
#define ll long long #define bug(x) cout<<#x<<"x="<<x<<endl using namespace std;
const int maxx = 1e5 + 5; const int mod = 1e9 + 7;
inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } int m,n; bool mp[105][105]; bool vis[105][105]; int ans[105][105]; int st[4][2]={{1,0},{-1,0}, {0,1},{0,-1}}; int stx,sty,enx,eny; int k; struct no{ int x,y,cnt,di; }; void so() { memset(vis,0,sizeof(vis));
cin>>n>>m; char c; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { cin>>c; if(c=='.') mp[i][j]=1; else mp[i][j]=0; } cin>>k>>sty>>stx>>eny>>enx;
vis[stx][sty]=1; queue<no> q; q.push({stx,sty,0,4}); while(!q.empty()) { no a=q.front(); if(a.x==enx&&a.y==eny) { if(a.cnt>k) continue; else { cout<<"yes\n"; return ; } } q.pop(); int xx,yy,cnt; for(int i=0;i<4;i++) { xx=a.x+st[i][0]; yy=a.y+st[i][1]; if(a.di==4) cnt=0; else if(a.di!=i) cnt=a.cnt+1; else if(a.di==i) cnt=a.cnt;
if(cnt>k) continue; if(xx>0&&xx<=n&&yy>0&&yy<=m&&mp[xx][yy]) { if(!vis[xx][yy]) { vis[xx][yy]=1; ans[xx][yy]=cnt; q.push({xx,yy,cnt,i}); } else { if(ans[xx][yy]>=cnt) { ans[xx][yy]=cnt; q.push({xx,yy,cnt,i}); } } } } }
cout<<"no\n"; return ; }
signed main() { int t; cin>>t; while(t--) { so(); } return 0; }
|