ZOJ 1649 BFS
来源:互联网 发布:java系统开发 编辑:程序博客网 时间:2024/05/18 13:06
#include <cstdio>#include <queue>#include <cstring>using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 2E2 + 10;const int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, { -1, 0}};struct Node{ int x, y; int step; bool operator<(const Node &oth)const { return step > oth.step; }};Node cur, Next;char mp[maxn][maxn];int n, m, Arrival[maxn][maxn], Startx, Starty;int BFS(){ priority_queue<Node>Q; cur.x = Startx; cur.y = Starty; cur.step = 0; Arrival[Startx][Starty] = 0; Q.push(cur); while (!Q.empty()) { cur = Q.top(); Q.pop(); if (mp[cur.x][cur.y] == 'a') return cur.step; for (int i = 0; i < 4; i++) { Next.x = cur.x + dir[i][0]; Next.y = cur.y + dir[i][1]; Next.step = cur.step + 1; if (mp[Next.x][Next.y] == 'x') Next.step++; if (mp[Next.x][Next.y] != '#' && Next.step < Arrival[Next.x][Next.y]) { Arrival[Next.x][Next.y] = Next.step; Q.push(Next); } } } return 0;}int main(int argc, char const *argv[]){ while (~scanf("%d%d", &n, &m)) { for (int i = 0; i <= m + 1; i++) mp[0][i] = mp[n + 1][i] = '#'; for (int i = 1; i <= n; i++) { scanf("%s", mp[i] + 1); mp[i][0] = mp[i][m + 1] = '#'; for (int j = 1; j <= m; j++) if (mp[i][j] == 'r') Startx = i, Starty = j; } memset(Arrival, INF, sizeof(Arrival)); int ans = BFS(); if (ans) printf("%d\n", ans); else printf("Poor ANGEL has to stay in the prison all his life.\n"); } return 0;}
这题简直有鬼。。。
0 0
- ZOJ 1649 Rescue (BFS)
- zoj 1649 rescue (bfs)
- zoj 1649 BFS
- ZOJ 1649 BFS
- ZOJ 1649 Resuce (BFS)
- zoj 1649 bfs
- zoj 1649 BFS
- ZOJ 1649 : Rescue - BFS
- zoj 1649 Rescue bfs
- ZOJ 1649 BFS
- zoj 1649 bfs
- ZOJ 1649 Rescue BFS水题
- ZOJ 1649 Rescue(BFS)
- ZOJ 1649 Rescue (BFS)
- ZOJ 1649:Rescue(BFS)
- zoj 1649 Rescue (bfs+队列)
- 简单BFS ZOJ 1649Rescue
- ZOJ 1649 Rescue(BFS)
- poj 1080
- Java设计模式——装饰者设计模式
- Codeforces Round #352 (Div. 2)
- win10 uwp 判断文件存在
- git warning: LF will be replaced by CRLF in 解决办法
- ZOJ 1649 BFS
- 教你如何迅速秒杀掉:99%的海量数据处理面试题
- 【css】所有的a标签设置为新窗口打开【原创】
- 设计模式之代理模式
- Linux线程中pthread_join和pthread_detach函数
- Java锁机制
- 第7周 C语言程序设计(新2版) 练习1-17 打印长度大于80个字符的所有输入行
- CodeForces - 140A New Year Table (数学几何&精度)大圆内能放几个小圆
- Jquery即点即改2