【优先队列】HDU Rescue
来源:互联网 发布:中国网络什么时候墙的 编辑:程序博客网 时间:2024/05/01 00:02
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1242
利用优先队列处理守卫的时间差
#include<cstdio>#include<iostream>#include<queue>#include<cstring>#include<algorithm>using namespace std; struct node{ friend bool operator< (node n1, node n2) { return n1.step > n2.step; } int x,y; int step;};priority_queue<node> q;int n,m;char map[220][220];int vis[220][220];int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};bool jud(int x,int y){ if(x>=0&&x<n&&y>=0&&y<m&&map[x][y]!='#'&&!vis[x][y]) return true; return false;}int bfs(node start){ while(!q.empty())q.pop(); node now,next; q.push(start); int i; while(!q.empty()){ now=q.top(); q.pop(); vis[now.x][now.y]=1; for(i=0;i<4;++i){ next.x=now.x+dir[i][0]; next.y=now.y+dir[i][1]; if(!jud(next.x,next.y))continue; if(map[next.x][next.y]=='x') next.step=now.step+2; else next.step=now.step+1; if(map[next.x][next.y]=='a') return next.step; q.push(next); } } return -1;} int main(){ int i,j; int ans; node start; while(scanf("%d%d\n",&n,&m)!=EOF){ ans=-1; memset(vis,0,sizeof(vis)); for(i=0;i<n;++i){ for(j=0;j<m;++j){ scanf("%c",&map[i][j]); } getchar(); } for(i=0;i<n;++i){ for(j=0;j<m;++j){ if(map[i][j]=='r'){ start.x=i,start.y=j; start.step=0; ans=max(ans,bfs(start)); } } } 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 Rescue
- hdu 1242 Rescue 优先队列
- hdu-1242-Rescue-优先队列
- HDU-1242Rescue(优先队列)
- HDU 1242 Rescue【优先队列】
- hdu 1242Rescue(bfs+优先队列)
- HDU 1242 Rescue(广搜+优先队列)
- hdu 1242 Rescue (优先队列+bfs)
- HDU 1242 Rescue(BFS +优先队列)
- hdu 1242 Rescue(bfs+优先队列)
- hdu 1242 Rescue (优先队列)
- 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优先队列)
- poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)
- Http协议原理解析第一篇
- hdu 1875 畅通工程再续
- 基于Spring的MVC框架设计与实现
- queue容器适配器
- 【优先队列】HDU Rescue
- 黑马程序员——内部类
- 浮点数(32位)转换为IEEE754的格式
- 一致性hash算法 - consistent hashing
- 如何在CSDN博客中编辑公式?
- USACO Section 1.3 PROB Calf Flac(最长回文子串)
- noncopyable
- 【算法导论学习-009】仅使用Random(0,1)实现Random(a,b)
- Java编程思想