ZOJ 1649 Rescue
来源:互联网 发布:十一选五遗漏数据作用 编辑:程序博客网 时间:2024/06/05 08:56
//http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649#include <iostream>#include <cstdio>#include <vector>#include <cstring>#include <cctype>#include <algorithm>#include <cmath>#include <cstdlib>#include <queue>#include <map>#define maxn 200 + 10#define INF 0x7fffffffusing namespace std;char g[maxn][maxn];int stx, sty;bool vis[maxn][maxn];int move[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};int n, m;struct POINT{ int cur; int x, y;};priority_queue<POINT> q;bool operator<(POINT a, POINT b){ return a.cur > b.cur;}int bfs(){ POINT tmp; memset(vis, false, sizeof(vis)); tmp.x = stx; tmp.y = sty; tmp.cur = 0; vis[stx][sty] = true; q.push(tmp); while(!q.empty()) { tmp = q.top(); q.pop(); for(int i = 0; i < 4; ++i) { int dcur = tmp.cur; int dx = tmp.x + move[i][0]; int dy = tmp.y + move[i][1]; if(dx >= 0 && dx < n && dy >= 0 && dy < m && g[dx][dy] != '#' && !vis[dx][dy]) { vis[dx][dy] = true; if(g[dx][dy] == 'a') return dcur+1; else if(g[dx][dy] == '.') { POINT t; t.cur = dcur+1; t.x = dx; t.y = dy; q.push(t); } else if(g[dx][dy] == 'x') { POINT t; t.cur = dcur+2; t.x = dx; t.y = dy; q.push(t); } } } } return -1;}int main(){ while(scanf("%d%d", &n, &m) != EOF) { while(!q.empty()) q.pop(); memset(vis, false, sizeof(vis)); for(int i = 0; i < n; ++i) { scanf("%s", g[i]); for(int j = 0; j < m; ++j) if(g[i][j] == 'r') stx = i, sty = j; } int ans = bfs(); if(ans == -1) puts("Poor ANGEL has to stay in the prison all his life."); else printf("%d\n", ans); } return 0;}
0 0
- zoj 1649 Rescue
- ZOJ 1649 Rescue
- zoj 1649 Rescue
- ZOJ 1649 Rescue (BFS)
- zoj 1649 rescue (bfs)
- ZOJ-1649-Rescue
- zoj 1649 Rescue
- ZOJ:1649 Rescue
- ZOJ 1649 Rescue
- ACM ZOJ 1649 (Rescue)
- ZOJ(1649)Rescue
- ZOJ 1649 Rescue
- zoj 1649 Rescue
- zoj 1649 Rescue
- ZOJ 1649 : Rescue - BFS
- ZOJ 1649 Rescue
- zoj 1649 Rescue
- zoj 1649 Rescue bfs
- getch getche getchar的区别和缓冲区的概念
- 关于使用UDP套接字进行本地进程通信
- 假期算法学习
- 同过apache-commons-id.jar生成32为主键id
- rdryfyuguiygiuti
- ZOJ 1649 Rescue
- 从计算机复试看中国教育——一个面试官的经历
- new delete问题
- java 泛型上下限的例子
- cache策略实现的原理(200、304返回码含义)
- Relative布局中的各个属性的含义
- UVALIve--6663--Count the Regions【离散化+搜索】
- rteyerut iturte
- hdu3584--Cube(三维树状数组)