搜索问题,纠结了两天了,求指教
http://acm.hdu.edu.cn/showproblem.php?pid=1728
是哪里错了,求帮助,给组不能通过的测试数据也行,谢谢了!
#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>using namespace std;struct Point{ int x; int y; Point() { this->x=0; this->y=0; } bool check(int m,int n); void move(int i); bool eq(Point p);};bool Point::check(int m,int n){ if(this->x>=0&&this->x<m&&this->y>=0&&this->y<n) { return true; } else { return false; }}void Point::move(int i){ int fx[4][2]={{0,-1},{1,0},{0,1},{-1,0}}; this->x+=fx[i][0]; this->y+=fx[i][1];}bool Point::eq(Point p){ if(this->x==p.x && this->y==p.y) { return true; } else { return false; }}char map[100][100]={0};int mk[100][100]={0};int m,n;Point Q[10240];bool bfs(Point s,Point e){ int h=0,f=0; Q[f++]=s; while(h<f) { if(Q[h].eq(e) && mk[Q[h].y][Q[h].x]>=0) { return true; } else if(mk[Q[h].y][Q[h].x]>0) { for(int i=0;i<4;i++) { Point np =Q[h]; np.move(i); while(np.check(m,n) && map[np.y][np.x]=='.' && mk[np.y][np.x]==-1) { mk[np.y][np.x]=mk[Q[h].y][Q[h].x]-1; Q[f++]=np; np.move(i); } } } h++; } return false;}int main(int argc, char *argv[]){ int num; while(scanf("%d",&num)!=EOF) { for(int i=0;i<num;i++) { memset(map,0,sizeof(map)); memset(mk,-1,sizeof(mk)); scanf("%d %d",&n,&m); for(int y=0;y<n;y++) { scanf("%s",map[y]); } int k,x1,y1,x2,y2; scanf("%d %d %d %d %d",&k,&x1,&y1,&x2,&y2); x1--;y1--;x2--;y2--; Point s,e; s.x=x1;s.y=y1; e.x=x2;e.y=y2; mk[s.y][s.x]=k+1; printf("%s\n",bfs(s,e)?"yes":"no"); } } return 0;}