标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18148 Accepted Submission(s): 4388
#include <iostream>
#include <queue>
#include<cstring>
using namespace std;
struct node
{
int x,y,t;
};
int vis[101][101];
char map[101][101];
int step[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
int x,y,x1,y1,n,m,k;
bool bfs()
{
memset(vis,0,sizeof(vis));
queue<node> q;
node now;
now.x=x;
now.y=y;
now.t=-1;
q.push(now);
vis[x][y]=1;
while(!q.empty())
{
now=q.front();
q.pop();
node next;
if(now.t>=k)continue;
for(int i=0; i<4; i++)
{
next.x=now.x+step[i][0];
next.y=now.y+step[i][1];
next.t=now.t+1;
while(1)
{
if(next.x<0||next.x>=m||next.y<0||next.y>=n)
break;
if(map[next.x][next.y]==‘*‘)
break;
if(next.x==x1&&next.y==y1)
return 1;
if(!vis[next.x][next.y])
{
q.push(next);
vis[next.x][next.y]=1;
}
next.x+=step[i][0];
next.y+=step[i][1];
}
}
}
return 0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>m>>n;
for(int i=0; i<m; i++)
cin>>map[i];
cin>>k>>y>>x>>y1>>x1;
x--;
y--;
x1--;
y1--;
if(bfs())
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/lengxia/p/4472442.html