HDU 1242 Rescue
来源:互联网 发布:开源房产cms 编辑:程序博客网 时间:2024/06/05 02:45
#include<stdio.h>#include<string.h>#include<queue>using namespace std;const int maxn = 1e3 + 5;const int INF = 0x3f3f3f3f;char mp[maxn][maxn];int vis[maxn][maxn];int dx[10] = {0,0,-1,1,1,1,-1,-1};int dy[10] = {1,-1,0,0,-1,1,-1,1};int n,m;struct node{int x,y;int step;node(int _x, int _y, int _step = 0): x(_x), y(_y),step(_step){}bool operator < (const node & i)const{return step > i.step;}};int main (){while (scanf("%d%d", &n, &m) != EOF){for (int i = 0; i < n; i++){for (int j = 0; j < m; j++){mp[i][j] = INF;}}for (int i = 0; i < n; i++){scanf("%s",mp[i]);}int sx,sy;for (int i = 0; i < n; i++){for (int j = 0; j < m; j++){if (mp[i][j] == 'a'){sx = i;sy = j;}}}priority_queue<node> que;que.push(node(sx,sy));memset(vis,0,sizeof(vis));vis[sx][sy] = 1;int ans = 0;while (!que.empty() ){node tem = que.top() ;que.pop() ;if (mp[tem.x ][tem.y ] == 'r'){ans = tem.step ;break;}for (int i = 0; i < 4; i++){int x = tem.x + dx[i];int y = tem.y + dy[i];if (x < 0 || y < 0 || x >= n || y >= m) continue;else if (vis[x][y])continue;else if (mp[x][y] == '.' || mp[x][y] == 'r') { // 开始忘了在这判断r,结果总是出错que.push(node(x,y,tem.step + 1)); vis[x][y] = 1;continue;}else if (mp[x][y] == '#')continue; //#不允许通过,题上好像没说else {que.push(node(x,y,tem.step + 2)); vis[x][y] = 1;}}}if (!que.empty() ){printf("%d\n",ans);}else printf("Poor ANGEL has to stay in the prison all his life.\n");}}
阅读全文
0 0
- hdu 1242 Rescue
- HDU-1242-Rescue
- HDU 1242 Rescue
- HDU-1242 Rescue
- hdu 1242 Rescue
- hdu 1242 Rescue<java>
- hdu 1242 rescue
- HDU-1242:Rescue
- HDU 1242 Rescue
- HDU 1242 Rescue
- hdu 1242 Rescue
- hdu 1242 Rescue
- hdu 1242 Rescue
- hdu 1242 Rescue
- hdu 1242 Rescue
- Rescue hdu 1242
- hdu-1242-Rescue
- Hdu 1242 Rescue
- 到底什么才是闭包
- 六角幻方
- 个人笔记 org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.
- Java入门基础之【对象和类】3
- Hibernate——配置文件中数据类型date与timestamp区别
- HDU 1242 Rescue
- 用R语言的MICE包对缺失数据进行多重插补(一)-- 缺失数据分析
- C++对象模型
- gym 101170 NWERC 2016 I Iron and Coal
- linux系统安装git,nodejs,mysql
- SAS篇-如何判断一个字段值是否为空?
- 重新解析 REST Service(REST Service 的最佳实践,第 1 部分)
- ORB-SLAM2在window下的配置 (2)
- 有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?