codevs 1215 迷宫
来源:互联网 发布:多得美工学院b段班 编辑:程序博客网 时间:2024/05/16 11:45
深度优先搜索
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>using namespace std;int mapp[17][17];int m,n;bool pd=0;void search(int x,int y){ if(mapp[x][y]==3){ cout<<"YES"<<'\n'; pd=1; return; } mapp[x][y]=1; //表示已经走过了 if(mapp[x][y+1]==0||mapp[x][y+1]==3)search(x,y+1); if(pd)return; if(mapp[x+1][y]==0||mapp[x+1][y]==3)search(x+1,y); if(pd)return; if(mapp[x-1][y]==0||mapp[x-1][y]==3)search(x-1,y); if(pd)return; if(mapp[x][y-1]==0||mapp[x][y-1]==3)search(x,y-1);}int main(){ cin>>m; char temp; for(int o=1;o<=m;++o){ pd=0; cin>>n; memset(mapp,-2,sizeof(mapp)); //-2表示地图外 for(int i=1;i<=n;++i){ for(int j=1;j<=n;++j){ cin>>temp; //读入地图 if(temp=='.'){ mapp[i][j]=0; } if(temp=='#'){ mapp[i][j]=1; //1表示墙 } if(temp=='s'){ mapp[i][j]=0; } if(temp=='e'){ mapp[i][j]=3; //3表示终点 } } } search(1,1); if(pd==0)cout<<"NO\n"; } return 0;}
阅读全文
0 0
- Codevs 1215 迷宫
- codevs 1215 迷宫
- CodeVS 1215 迷宫 题解
- codevs 1215 迷宫
- 【codevs 1215】迷宫
- Codevs 1215 迷宫 裸BFS
- Codevs 1215 迷宫(DFS)
- codevs 1215_迷宫_bfs
- Codevs 1629 01迷宫
- CodeVS 3344 迷宫 题解
- codevs 1215 迷宫 广搜bfs 深搜dfs
- Codevs 2855 游乐园的迷宫
- 20160318 CodeVS 1215 走迷宫,3286 火柴排队,2618 核电站问题
- Codevs 1337 银行里的迷宫
- codevs 1337 银行里的迷宫
- Codevs 1337 银行里的迷宫
- 1215 迷宫
- 1215 迷宫
- rem单位换算
- redis-server.exe redis.windows.conf 报配置文件参数错误
- CXF实现webservice (一)
- Java虚拟机常用指令(二十二)
- C语言关键字Inline
- codevs 1215 迷宫
- Kotlin-18.对象(object expressions/declarations)
- 74、多态性(129)
- 路由表生成算法
- Java反射机制详解
- 剑指offer——数组中的逆序数_____(归并排序)
- 大二这个年纪
- 前端学习笔记4:CSS的继承、层叠和特殊性
- HTML常用标签小结