标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19656 Accepted Submission(s):
4783
#include<stdio.h>
#include<string.h>
#include<queue>
#define MAX 110
using namespace std;
char map[MAX][MAX];
int vis[MAX][MAX];
int n,m;
int w,x1,x2,y1,y2;
void getmap()
{
int i,j;
for(i=1;i<=n;i++)
{
getchar();
for(j=1;j<=m;j++)
{
scanf("%c",&map[i][j]);
}
}
}
struct node
{
int x,y;
};
int judge(int x,int y)
{
if(x>0&&x<=n&&y>0&&y<=m&&map[x][y]!=‘*‘)
return 1;
return 0;
}
void bfs()
{
int move[4][2]={0,1,0,-1,1,0,-1,0};
int i,j,ok=0;
queue<node>q;
node beg,end;
beg.x=x1;
beg.y=y1;
q.push(beg);
while(!q.empty())
{
end=q.front();
q.pop();
if(end.x==x2&&end.y==y2)
{
if(vis[end.x][end.y]<=w)
{
printf("yes\n");
ok=1;
}
else
break;
}
else
{
for(i=0;i<4;i++)
{
beg.x=end.x+move[i][0];
beg.y=end.y+move[i][1];
while(judge(beg.x,beg.y))
{
if(vis[beg.x][beg.y]==-1)
{
vis[beg.x][beg.y]=vis[end.x][end.y]+1;
q.push(beg);
}
beg.x+=move[i][0];//沿着这个方向继续走
beg.y+=move[i][1];
}
}
}
}
if(!ok)
printf("no\n");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
getmap();
scanf("%d%d%d%d%d",&w,&y1,&x1,&y2,&x2);
memset(vis,-1,sizeof(vis));
bfs();
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4718298.html