标签:class blog code 2014 string os
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
#define ll __int64
#define mod 1000000007
using namespace std;
struct node
{
int x,y,cnt;
}now,tmp;
int dx[]={1,-1,0,0};
int dy[]={0,0,-1,1};
char mp[110][110];
int vis[110][110],k,x1,x2,yy1,y2,n,m;
int ok(int x,int y)
{
if(x>=0&&x<n&&y>=0&&y<m&&mp[x][y]!='*') return 1;
return 0;
}
int bfs()
{
queue<node> q;
now.x=x1;
now.y=yy1;
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
for(int i=0;i<4;i++)
{
tmp.x=now.x+dx[i];
tmp.y=now.y+dy[i];
while(ok(tmp.x,tmp.y))//同一方向走到低 保证每次到该位置转弯次数是最少的
{
if(vis[tmp.x][tmp.y]==-1)
{
vis[tmp.x][tmp.y]=vis[now.x][now.y]+1;
if(tmp.x==x2&&tmp.y==y2&&vis[tmp.x][tmp.y]<=k) return 1;
q.push(tmp);
}
tmp.x=tmp.x+dx[i];
tmp.y=tmp.y+dy[i];
}
}
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%s",mp[i]);
scanf("%d%d%d%d%d",&k,&yy1,&x1,&y2,&x2);
x1--;x2--;yy1--;y2--;
memset(vis,-1,sizeof vis);
if(bfs()) printf("yes\n");
else printf("no\n");
}
return 0;
}
标签:class blog code 2014 string os
原文地址:http://blog.csdn.net/u011032846/article/details/34817557