ACM hdu 1175 连连看 WA 求解释 或 就错误的数据
http://acm.hdu.总是WA
跪求大神 解释哪里有问题
或者 给我一个 得不出正确结果的数据
我的代码
程序代码:#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node
{
int x,y;
}dui[50000000];
int n,m;
int map[1010][1010];
int mark[1010][1010];
int vis[1010][1010][4];
int dir[4][2]={0,1,1,0,0,-1,-1,0};
int s_x,s_y,e_x,e_y;
void bfs()
{
int head,tail;
int i,j;
struct node now,next;
memset(mark,0,sizeof(mark));
memset(vis,0,sizeof(vis));
for(i=0;i<1002;i++)
for(j=0;j<1002;j++)
mark[i][j]=100000000;
head=tail=0;
dui[tail].x=s_x;
dui[tail++].y=s_y;
mark[s_x][s_y]=-1;
vis[s_x][s_y][0]=1;
while(head<tail)
{
now.x=dui[head].x;
now.y=dui[head++].y;
for(i=0;i<4;i++)
{
next.x=now.x+dir[i][0];
next.y=now.y+dir[i][1];
while(next.x>=0 && next.y>=0 && next.x<n && next.y<m && map[next.x][next.y]==0 && vis[next.x][next.y][i]==0)
{
if(mark[next.x][next.y]>=mark[now.x][now.y]+1)
mark[next.x][next.y]=mark[now.x][now.y]+1;
else break;
vis[next.x][next.y][i]=1;
dui[tail].x=next.x;
dui[tail++].y=next.y;
next.x+=dir[i][0];
next.y+=dir[i][1];
}
}
}
return ;
}
int main()
{
int i,j;
int q,ff_x,ff_y,ans;
int flag;
while(scanf("%d%d",&n,&m),n||m)
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
scanf("%d",&map[i][j]);
}
scanf("%d",&q);
while(q--)
{
scanf("%d%d%d%d",&s_x,&s_y,&e_x,&e_y);
ans=100000000;
flag=1;
s_x--; s_y--; e_x--; e_y--;
if(map[s_x][s_y]==0 || map[e_x][e_y]==0 ||(map[s_x][s_y]!=map[e_x][e_y]) || (s_x==e_x && e_y==s_y))
printf("NO\n");
else
{
bfs();
for(i=0;i<4;i++)
{
ff_x=e_x+dir[i][0];
ff_y=e_y+dir[i][1];
if(ff_x<0 || ff_y<0 || ff_x>=n || ff_y>=m) continue;
if( (i==0 && vis[ff_x][ff_y][2]) || (i==1 &&vis[ff_x][ff_y][3]) || (i==2 && vis[ff_x][ff_y][0] ) ||(i==3 && vis[ff_x][ff_y][1]) )
flag=0;
if(ans>mark[ff_x][ff_y]+flag) ans=mark[ff_x][ff_y]+flag;
}
if(ans>2) printf("NO\n");
else printf("YES\n");
}
}
}
return 0;
}









