[BFS] Zjut CPP 1907 破解迷宫
来源:互联网 发布:腾讯大数据 编辑:程序博客网 时间:2024/06/05 05:43
简单BFS
#include <iostream>#include <queue>using namespace std;int m,n;char str[105][105];int ps[4][2]={1,0,0,-1,-1,0,0,1};struct Node{int x;int y;};Node s,e,r;queue <Node> qu;int main(){int t;cin>>t;for (;t>=1;t--){cin>>n>>m;bool found=false;for (int i=0;i<n;i++)for (int j=0;j<m;j++){cin>>str[i][j];if (str[i][j]=='M')str[i][j]='X';else if (str[i][j]=='S')s.x=i,s.y=j;else if (str[i][j]=='T')e.x=i,e.y=j;}qu.push(s);while (!qu.empty() && !found){s=qu.front();qu.pop();for (int p=0;p<4;p++){r.x=s.x+ps[p][0];r.y=s.y+ps[p][1];if (r.x>=0 && r.y>=0 && r.x<n && r.y<m && str[r.x][r.y]!='X'){if (str[r.x][r.y]=='T'){found=true;break;}str[r.x][r.y]='X';qu.push(r);}}}if (found)cout<<"YES\n";else cout<<"NO\n";}return 0;}
0 0
- [BFS] Zjut CPP 1907 破解迷宫
- ZJUT 1423 地下迷宫(期望DP&高斯消元)
- ZJUT 地下迷宫 (高斯求期望)
- BFS~~~迷宫
- BFS(迷宫)
- 迷宫-BFS
- BFS------迷宫
- 迷宫-BFS
- zujt ZJUT 1423 地下迷宫 高斯消元法 概率DP
- hdu1728 逃离迷宫(bfs)
- POJ3984 迷宫问题 BFS
- 经典迷宫问题BFS
- 迷宫问题 bfs
- 迷宫问题BFS暴搜
- BFS走迷宫
- BFS | 3984 | 迷宫问题
- HDU1728:逃离迷宫(BFS)
- hncu1102:迷宫问题(BFS)
- 关于Bitmap
- import,reload,__import__在python中的区别
- API(2)
- android布局文件 merge 标签的使用
- 强连通分量
- [BFS] Zjut CPP 1907 破解迷宫
- 解决:对 PInvoke 函数的调用导致堆栈不对称问题
- Cinder meeting 2015.10.16
- 基于Spring2.5.6搭建技术开发框架
- Android中webview和js之间的交互
- css属性:hover
- mysql sql中类型转换引起的索引无法使用的问题
- struts2的namespace
- Oracle 10g RAC TAF介绍