hdu 1242
来源:互联网 发布:周杰伦听妈妈的话知乎 编辑:程序博客网 时间:2024/06/07 05:10
用到优先队列的BFS,遇到X加上2就可以了
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<queue>using namespace std;char map[205][205];int judge[205][205];int move[4][2]={{-1,0},{1,0},{0,-1},{0,1}};struct print{ int x,y; int step; friend bool operator < (const print &a,const print &b) //时间小的先出队 { return a.step>b.step; }};int main(){ int n,m,sx,sy,fx,fy,ans; while(scanf("%d%d",&n,&m)!=EOF){ memset(judge,0,sizeof(judge)); priority_queue<print> q; for(int i=0;i<n;i++) scanf("%s",map[i]); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(map[i][j]=='a'){ sx=i; sy=j; } } } //while(q.size()) q.pop(); ans=-1; print s; s.x=sx; s.y=sy; s.step=0; q.push(s); judge[sx][sy]=1; while(!q.empty()){ print now,next; now=q.top(); //judge[now.x][now.y]=1; q.pop(); if(map[now.x][now.y]=='r'){ ans=now.step; break; } for(int i=0;i<4;i++){ next.x=now.x+move[i][0]; next.y=now.y+move[i][1]; if(judge[next.x][next.y]==0&&map[next.x][next.y]!='#'&&0<=next.x&&next.x<n&&0<=next.y&&next.y<m){ judge[next.x][next.y]=1; if(map[next.x][next.y]=='x') next.step=now.step+2; else next.step=now.step+1; q.push(next); } } } if(ans==-1){ printf("Poor ANGEL has to stay in the prison all his life.\n"); } else{ printf("%d\n",ans); } } return 0;}
0 0
- hdu 1242
- hdu 1242
- HDU 1242
- hdu 1242
- hdu-1242
- HDU 1242
- hdu--1242
- HDU 1242
- HDU 1242
- HDU 1242
- hdu 1242
- HDU 1242
- hdu 1242
- HDU 1242
- hdu 1242 Rescue
- hdu 1242 bfs
- dfs hdu 1242
- HDU-1242-Rescue
- 杭电acm之1516--String Distance and Transform Process
- POJ 1258
- Samba服务器搭建
- Linux学习笔记之——普通用户使用sudo命令
- ubuntu 安装卸载软件方法
- hdu 1242
- acm之路 之插入排序
- Subsets
- 《Mali OpenCL SDK v1.1.0》教程样例之一“Hello World”
- 今年暑假不AC-贪心算法
- 我的新博客不断更新中
- Fedora20 安装fcitx 搜狗输入法 卸载ibus
- 详细程序注解学OpenCL一 环境配置和入门程序
- 关于C有符号数数值溢出