Help the Princess! BFS队列
来源:互联网 发布:阿里云取消手机绑定 编辑:程序博客网 时间:2024/06/14 11:08
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <cmath>using namespace std;const int maxn = 210;const int inff = 1000000;char maze[maxn][maxn];int ans1, ans2;int zou[2][4] = { 0,0,1,-1,1,-1,0,0 };int vis[maxn][maxn];struct node{int x, y, bushu;};void bfs(int x, int y,int h,int w){queue<node> q;node pos, ne;pos.x = x; pos.y = y; pos.bushu = 0;q.push(pos);vis[x][y] = 1;while (!q.empty()){pos = q.front();q.pop();for (int i = 0; i<4; i++){ne.x = pos.x + zou[0][i];ne.y = pos.y + zou[1][i];if (!vis[ne.x][ne.y] && ne.x >= 1 && ne.x <= h && ne.y >= 1 && ne.y <= w && maze[ne.x][ne.y] != '#'){ne.bushu = pos.bushu + 1;vis[ne.x][ne.y] = 1;if (maze[ne.x][ne.y] == '@')ans1 = min(ne.bushu, ans1);else if (maze[ne.x][ne.y] == '$')ans2 = min(ne.bushu, ans2);q.push(ne);}}if (ans1 < inff&& ans2 < inff) break;}}int main(){int h, w, x, y;scanf("%d%d", &h, &w); ans1 = ans2 = inff;getchar();for (int i = 1; i <= h; i++){for (int j = 1; j <= w; j++){scanf("%c", &maze[i][j]);if (maze[i][j] == '%'){x = i; y = j;}}getchar();}bfs(x, y,h,w);if (ans1 < ans2) printf("Yes\n");else printf("No\n");return 0;}
阅读全文
0 0
- Help the Princess! BFS队列
- [JAG practice] B - Help the Princess! bfs
- hdu1026 Ignatius and the Princess I (优先队列 BFS)
- hdu 1026 Ignatius and the Princess I bfs+优先级队列
- hdu 1026 Ignatius and the Princess I(优先队列+BFS)
- HDU1026:Ignatius and the Princess I(BFS+优先队列)
- hdu 1026 Ignatius and the Princess I 优先队列 + bfs
- HDU 1026 Ignatius and the Princess I - BFS + 优先队列
- hdu1026 Ignatius and the Princess I(BFS+优先队列)
- HDU 1026 Ignatius and the Princess I 优先队列 +BFS.
- HDU 1026 Ignatius and the Princess I(优先队列bfs)
- HDU 1026 Ignatius and the Princess I(BFS+优先队列)
- hdu1026Ignatius and the Princess I(BFS + 优先队列)
- HDU1026 Ignatius and the Princess I(优先队列+BFS)
- HDU 1026 Ignatius and the Princess I bfs优先队列
- HDU 1026 Ignatius and the Princess I BFS优先队列
- HDU 1026 Ignatius and the Princess I BFS 优先队列
- (2016弱小联盟十一专场10.3) Help the Princess! BFS
- java操作Excel:技巧
- 膨胀腐蚀-OpenCL加速及kernel变成二进制文件
- python 定时任务框架
- ajax调用json数据并显示至columns表格中
- DCMTK实现Dicom CT图片读取CT值图像
- Help the Princess! BFS队列
- UE4多播代理
- 启用idea的SVN插件
- 哈希表
- 如何更改ckeditor编辑器默认文字的大小
- 十大Intellij IDEA快捷键
- 矩形
- windows中eclipse里将tomcat控制台日志输出到catalina.out中
- 关于CSS实现水平垂直居中