搜索题,找了好久没找到错误,请指教
杭电 1728#include"stdio.h"
#include"iostream"
#include"string.h"
#include"queue"
using namespace std;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
char ch[120][120];
int g[120][120];
int m,n,x2,y2,x1,y1,k;
struct point
{
int x,y,time,s;
};
queue<point> Q;
int bfs(point z)
{
int a,b,i,j,t;
while(!Q.empty())
Q.pop();
Q.push(z);
for(i=0;i<110;i++)
for(j=0;j<110;j++)
g[i][j]=100000000;
g[y1][x1]=0;
point hd;
while(!Q.empty())
{
hd=Q.front();
Q.pop();
for(i=0;i<4;i++)
{
int a=hd.x+dx[i],b=hd.y+dy[i];
if(a<0||a>=n||b<0||b>=m||ch[b][a]=='*')
continue ;
else
{
point t1;
t1.x=a;
t1.y=b;
if(dx[i]==0) t1.s=1;
else t1.s=2;
if(hd.s == -1) t1.time = 0;
else if(hd.s==t1.s)t1.time=hd.time;
else t1.time=hd.time+1;
if(t1.time<g[b][a]&&t1.time <= k)
{
g[b][a]=t1.time;
Q.push(t1);
}
}
}
}
return g[y2][x2];
}
int main()
{
int t,i,p;
while(cin>>t)
{
while(t--)
{
memset(ch,0,sizeof(ch));
cin>>m>>n;
for(i=0;i<m;i++)
{
cin>>ch[i];
}
// for(i = 0;i < m;i++)
// printf("%s\n",ch[i]);
cin>>k>>x1>>y1>>x2>>y2;
x1--;
x2--;
y1--;
y2--;
point start;
start.x=x1;
start.y=y1;
start.time=0;
start.s=-1;
p=bfs(start);
if(p<=k)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
// cout<<p<<endl;
}
}
return 0;
}