设为首页 加入收藏

TOP

HDU 2612 -Find a way (注意细节的BFS)
2015-07-24 05:46:04 来源: 作者: 【 】 浏览:4
Tags:HDU 2612 -Find way 注意 细节 BFS

题目链接:Find a Way

题目不难,前几天做,当时准备写双向BFS的,后来处理细节上出了点问题,赶上点事搁置了,今天晚上重写的,没用双向,用了两次BFS搜索,和双向BFS 道理差不多,只是这题有个小坑,需要注意

1.Y不能经过M,M不能经过Y,也就是说有Y和M的格子,可以默认为是墙

2.必须是Y和M都能到达的KFC才行,只是其中一个到达不行


例如下列数据;答案既不是22 也不是 88 而是110,左下角的KFC满座条件

5 5
Y..#@
...M.
....#
.....
@....
小小的坑我了一下。。。。

感谢昵称: zstu_JayYe杰 不是看了他在Discuss板里的留言,估计我也想不到

31MS 852K

代码很渣,哗哗。。

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        const int N = 1e6; const int M = 220; using namespace std; char mapp[M][M]; bool vis1[M][M],vis2[M][M]; int dis1[M][M],dis2[M][M],n,m,l; struct node { int x,y,a; node() { x = 0; y = 0;a = 0; } }; struct noDe{ int x,y; }kfc[40010]; int mv[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; void BFS(int x,int y,bool visit[M][M],int ans[M][M]) { node f,t; queue
       
        q; visit[x][y]=true; f.a = 0; f.x=x; f.y=y; q.push(f); while(!q.empty()) { t = q.front(); q.pop(); if(mapp[t.x][t.y]=='@') ans[t.x][t.y] = t.a; for(int i=0;i<4;i++) { f.x=t.x+mv[i][0]; f.y=t.y+mv[i][1]; if(!visit[f.x][f.y]&&0<=f.x&&f.x
        
          dis1[kfc[i].x][kfc[i].y] + dis2[kfc[i].x][kfc[i].y]) if(dis1[kfc[i].x][kfc[i].y]!=0&&dis2[kfc[i].x][kfc[i].y]!=0) minn = dis1[kfc[i].x][kfc[i].y] + dis2[kfc[i].x][kfc[i].y]; } printf("%d\n",minn*11); } return 0; } 
        
       
      
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA 1069 - Always an integer(数.. 下一篇C++语言笔记系列之十四――继承后..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: