设为首页 加入收藏

TOP

hdu1180诡异的楼梯……bfs走迷宫……wa了16次,我太渣了
2015-07-20 18:07:37 】 浏览:2481
Tags:hdu1180 诡异 楼梯 bfs 迷宫
#include
  
   
#include
   
     #include
    
      using namespace std; int row,line,xx[4]={-1,1,0,0},yy[4]={0,0,-1,1}; char map[100][100]; bool vis[100][100]; struct node { int x,y,step; }st; void init() { int i,j; bool flag=1; for(i=0;i
     
      =row||y>=line||vis[x][y]||map[x][y]=='*') return 0; return 1; } void bfs() { int i; queue
      
       qq; node t1,t2; qq.push(st); while(qq.size()) { t1=qq.front(); qq.pop(); if(map[t1.x][t1.y]=='T') { printf("%d\n",t1.step); return; } for(i=0;i<4;i++) { t2=t1; t2.x+=xx[i]; t2.y+=yy[i]; t2.step++; if(!iscan(t2.x,t2.y)) continue; if(map[t2.x][t2.y]=='.'||map[t2.x][t2.y]=='T') { vis[t2.x][t2.y]=1; qq.push(t2); } else if((map[t2.x][t2.y]=='|'&&!(t1.step&1))||(map[t2.x][t2.y]=='-'&&(t1.step&1))) { if(i>1) { t2=t1; t2.step++; qq.push(t2); continue; } t2.x+=xx[i]; if(!iscan(t2.x,t2.y)) continue; vis[t2.x][t2.y]=1; qq.push(t2); } else { if(i<2) { t2=t1; t2.step++; qq.push(t2); continue; } t2.y+=yy[i]; if(!iscan(t2.x,t2.y)) continue; vis[t2.x][t2.y]=1; qq.push(t2); } } } } int main() { while(scanf("%d%d",&row,&line)!=EOF) { init(); bfs(); } }
      
     
    
   
  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Effective C++ Item 45 运用成员.. 下一篇Effective C++ Item 44 将与参数..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目