您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> C/C++ >> hdu 1242 广搜总是wa求高手帮助。。

hdu 1242 广搜总是wa求高手帮助。。

来源:网络整理     时间:2016/7/14 23:00:22     关键词:

关于网友提出的“ hdu 1242 广搜总是wa求高手帮助。。”问题疑问,本网通过在网上对“ hdu 1242 广搜总是wa求高手帮助。。”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: hdu 1242 广搜总是wa求高手帮助。。
描述:

我的思路是用广搜 但是不设定标记。直到找出最小的http://acm.hdu.edu.cn/showproblem.php?pid=1242我没学过C++,我试了好几组数据都对可是总是wa~弄了一天了,~请高手赐教支持错误或者指点思路,本人不甚感激。
详情看代码吧:

#include 
#include 
#include
#define max 201
#define maxsize 40005
typedef struct
{
      int x,y;
}Queue;
char graph[max][max];
int step[max][max];
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int bfs(int n,int m,Queue np);
int main()
{
    int n,m;
    Queue np;
    while(scanf("%d%d%*c",&n,&m)!=EOF)
    {
          memset(graph,0,sizeof(graph));
          memset(step,0,sizeof(step));
          int i,j;
          for(i=0;i<>
          {
                gets(graph[i]);
                for(j=0;j<>
                        if(graph[i][j]=='a')
                         {
                                  np.x=i;
                                  np.y=j;
                         }
          }
          int res=bfs(n,m,np);
          if(res)
            printf("%d\n",res);
          else
            printf("Poor ANGEL has to stay in the prison all his life.\n");
    }
    return 0;
}
int bfs(int n,int m,Queue np)
{
      Queue q[maxsize],cp;
      int res=0,front,rear,i;
      fr />       q[rear++]=np;
      step[np.x][np.y]=0;
      while(front<>
      {
            np=q[front++];
            for(i=0;i<4;i++)
            {
                  cp.x=np.x+dir[i][0];
                  cp.y=np.y+dir[i][1];
                  if(cp.x>=0&&cp.x=0&&cp.y<>
                  {
                        if((step[cp.x][cp.y]>step[np.x][np.y]+1)||step[cp.x][cp.y]==0)
                              {
                                    step[cp.x][cp.y]=step[np.x][np.y]+1;
                                    q[rear++]=cp;//入队
                              }
                        if(graph[cp.x][cp.y]=='r')
                              {
                                    res=step[cp.x][cp.y];
                              }
                        if(graph[cp.x][cp.y]=='x')
                        {
                              step[cp.x][cp.y]++;
                        }
                  }
            }
      }
      return res;
}

以上介绍了“ hdu 1242 广搜总是wa求高手帮助。。”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2645968.html

相关图片

相关文章