HDU 1242 Rescue BFS+优先队列
来源:互联网 发布:刺客信条mac 编辑:程序博客网 时间:2024/06/16 16:02
题目链接:点击打开链接http://acm.hdu.edu.cn/showproblem.php?pid=1242
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>using namespace std;const int N=220;int n,m,stx,sty,endx,endy;char mp[N][N];int vis[N][N]; int f[4][2]={{0,-1},{-1,0},{0,1},{1,0}};//kengstruct node{int x;int y;int t; friend bool operator < (const node &a,const node &b) {return a.t>b.t;//大于是从小往大排 }} ;bool isbound(int x,int y){if(x>0&&x<=n&&y>0&&y<=m&&mp[x][y]!='#')return true;else return false;}void BFS(int x,int y){priority_queue<node>Q;memset(vis,0,sizeof(vis));while(!Q.empty()){Q.pop();}node p,q;p.x=x;p.y=y;p.t=0;vis[p.x][p.y]=1;Q.push(p); while(!Q.empty()){p=Q.top();Q.pop() ;if(p.x==endx&&p.y==endy){printf("%d\n",p.t);return;}for(int i=0;i<4;i++){q.x=p.x+f[i][0];q.y=p.y+f[i][1];if(!isbound(q.x,q.y)) continue;if(vis[q.x ][q.y ]==1) continue;vis[q.x ][q.y]=1;if(mp[q.x ][q.y]=='x')q.t =p.t + 2;elseq.t =p.t + 1;Q.push(q);}}printf("Poor ANGEL has to stay in the prison all his life.\n");}int main(){while(~scanf("%d%d",&n,&m)) {for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>mp[i][j];if(mp[i][j]=='r'){stx=i;sty=j;}else if(mp[i][j]=='a'){endx=i;endy=j;}}}BFS(stx,sty);}return 0;}
0 0
- hdu 1242Rescue(bfs+优先队列)
- hdu 1242 Rescue (优先队列+bfs)
- HDU 1242 Rescue(BFS +优先队列)
- hdu 1242 Rescue(bfs+优先队列)
- HDU 1242 Rescue 优先队列+BFS
- HDU 1242 Rescue(BFS,优先队列)
- HDU 1242 Rescue(BFS+优先队列)
- hdu-1242-Rescue(优先队列 BFS)
- HDU 1242 Rescue(优先队列 + 多源BFS)
- [ACM] hdu 1242 Rescue (BFS+优先队列)
- hdu 1242 Rescue(BFS优先队列)
- HDU 1242 Rescue (BFS+优先队列)
- hdu 1242 Rescue (bfs+优先队列)
- HDU 1242 Rescue (BFS+优先队列)
- HDU 1242 Rescue(优先队列+bfs)
- HDU 1242 Rescue【优先队列BFS】
- hdu 1242 Rescue(BFS+优先队列)
- hdu 1242 Rescue bfs+优先队列priority
- 如何在3个月内拥有3年的工作经验?
- 总结一下遇到的各种核函数~
- 省市区字典
- block 块实现传值
- Linux 管理 之Sort详解
- HDU 1242 Rescue BFS+优先队列
- 世界那么多大 我想去看看
- 计算机图形学导论(1)-基础数学
- 网络图片抓取--web开发批量盗图!!!!!
- android开发-定时器
- iOS 动画Animation详解, UIView动画(UIView属性动画,UIViewTransition动画,UIView Block动画),CALayer动画(CABasicAnima...)
- GetElem()
- 划分树
- http关闭连接