#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
using namespace std;
const int MAXN=105;
const int MAXM=105;
int n,m,i,T;
int done[MAXN][MAXN];
int sx,sy,ex,ey;
char map[MAXN][MAXN];
int dx[]={0,0,1,-1};//右左下上
int dy[]={1,-1,0,0};
struct node
{
int x,y,w,dir;
node(int xx=0,int yy=0,int ww=0,int di=0)
{
x=xx;y=yy;w=ww;dir=di;
}
};
bool is_ill(int x,int y)
{
if(x<0||x>=n||y<0||y>=m)return 1;
return 0;
}
int bfs()
{
int i;
queue<node>q;
memset(done,0,sizeof(done));
q.push(node(sx,sy,-1,-1));
done[sx][sy]=1;
while(!q.empty())
{
node e=q.front();q.pop();
if(e.w>=T)continue;
for(i=0;i<4;i++)
{
int curx=e.x+dx[i];
int cury=e.y+dy[i];
int curw=e.w+1;
while(!is_ill(curx,cury)&&map[curx][cury]!='*')
{
if(curx==ex&&cury==ey)return 1;
if(done[curx][cury]){curx+=dx[i];cury+=dy[i];continue;}
q.push(node(curx,cury,curw));
done[curx][cury]=1;
curx+=dx[i];
cury+=dy[i];
}
}
}
return 0;
}
int main()
{
//freopen("123.txt","r",stdin);
int N;
cin>>N;
while(N--)
{
scanf("%d%d",&n,&m);
gets(map[0]);
for(i=0;i<n;i++)
gets(map[i]);
scanf("%d%d%d%d%d",&T,&sy,&sx,&ey,&ex);
sy-=1;sx-=1;
ex-=1;ey-=1;
if(bfs())printf("yes\n");
else printf("no\n");
}
return 0;
}
HDU1728 逃离迷宫 BFS
最新推荐文章于 2021-12-18 22:31:00 发布