#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
using namespace std;
int n,m,k,sx,sy,ex,ey;
char graph[105][105];
bool vis[105][105];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
struct node{
int x,y,turn;
node(int x,int y,int turn):x(x),y(y),turn(turn){}
};
void input(){
scanf("%d%d",&n,&m);
memset(vis,false,sizeof(vis));
for(int i=0;i<n;i++)
scanf(" %s",graph[i]);
scanf("%d%d%d%d%d",&k,&sy,&sx,&ey,&ex);
sx--,sy--,ex--,ey--;
}
void bfs(){
node tmp(sx,sy,-1);
vis[sx][sy] = 1;
queue<node> q;
q.push(tmp);
bool flag = false;
while(!q.empty()){
node cur = q.front();
q.pop();
if(cur.x==ex && cur.y==ey && cur.turn<=k){
flag = true;
break;
}
if(cur.turn>k) continue;
for(int i=0;i<4;i++){
int xx = cur.x+dx[i];
int yy = cur.y+dy[i];
while(xx>=0 && xx<n && yy>=0 && yy<m && graph[xx][yy]=='.'){
if(!vis[xx][yy]){
node t(xx,yy,cur.turn+1);
q.push(t);
vis[xx][yy] = true;
}
xx += dx[i];
yy += dy[i];
}
}
}
if(flag)
printf("yes\n");
else
printf("no\n");
}
int main(){
int t;
scanf("%d",&t);
while(t--){
input();
bfs();
}
return 0;
}
此题关键点在于,一个点经过一次后,在后面的遍历中也可以经过该点,只要是目标在于使得转弯次数最少是约束条件
03-21
1573
09-14