【杭电oj1242】Rescue
来源:互联网 发布:淘宝专柜小样是真的吗 编辑:程序博客网 时间:2024/05/17 23:34
在下是菜鸡,一个细节没注意到,非void函数是要有返回值的,可是我就一直没加那个return -1;一直哇,桑心。希望以后我能避免犯这种错误。
DFS代码我也会贴上的,很快。
BFS+优先队列:
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;const int N = 210;char c[N][N];bool vis[N][N];int n,m,x,y,ex,ey;int px[4]= {1,-1,0,0};int py[4]= {0,0,-1,1};struct node { int tx,ty; int time; bool friend operator<(node A,node B) { return A.time>B.time; }} s;int dfs(int u,int v) { s.tx=u,s.ty=v,s.time=0; priority_queue<node>Q; Q.push(s); vis[u][v]=1; while(!Q.empty()) { node now; now=Q.top(); Q.pop(); if(now.tx==ex&&now.ty==ey) { return now.time; } for(int l=0; l<4; l++) { node end; end.tx=now.tx+px[l]; end.ty=now.ty+py[l]; end.time=now.time; if(c[end.tx][end.ty]!='#'&&!vis[end.tx][end.ty]&&end.tx>=0&&end.ty>=0&&end.tx<n&&end.ty<m) { if(c[end.tx][end.ty]=='x') end.time+=2; else end.time++; vis[end.tx][end.ty]=1; Q.push(end); } } } return -1;}int main() { while(scanf("%d%d",&n,&m)!=EOF) { memset(vis,false,sizeof(vis)); for(int l=0; l<n; l++) { scanf("%s",c[l]); } for(int i=0; i<n; i++) for(int j=0; j<m; j++) { if(c[i][j]=='r') x=i,y=j; if(c[i][j]=='a') ex=i,ey=j; } int ans=dfs(x,y); if(ans==-1) printf("Poor ANGEL has to stay in the prison all his life.\n"); else printf("%d\n",ans); } return 0;}
http://acm.hdu.edu.cn/showproblem.php?pid=1242
0 0
- 【杭电oj1242】Rescue
- 杭电1242---Rescue
- 杭电1242 rescue
- 杭电1242 Rescue
- 【杭电】[1242]Rescue
- 杭电 HDU 1242 Rescue
- hdu 杭电 1242 Rescue
- 杭电1242Rescue(bfs)
- 杭电 oj Rescue 1242
- 杭电1242-Rescue-DFS
- 杭电1242--Rescue--DFS 详解
- 杭电 1242 Rescue(广搜)
- 杭电1242Rescue(深搜)
- 【搜索之BFS + 优先队列】杭电 hdu 1242 Rescue
- 杭电1242--Rescue--BFS 广度优先算法详解
- 杭电1242Rescue题(bfs+优先队列)
- 杭电1242--Rescue(BFS+优先队列)
- 杭电 rescue(经典广搜)(深搜广搜对比)
- storm安装
- Android中的Attr、Style和Theme详解
- Codeforces Round #207 (Div. 2) C - Knight Tournament
- 了解程序编译、运行过程
- 进制转换
- 【杭电oj1242】Rescue
- 【JAVA】多态
- 5.7 编写一个程序,其中有一个函数指针*parea,通过它分别指向计算圆的面积函数 circle 和矩形面积函数 rect 来计算给定圆的面积和矩形面积。
- VMware虚拟机安装步骤
- 首次接触Oracle
- Q 统计量的计算
- Struts2.3+Spring3.2.8+Hibernate4.1全注解配置
- 6.5 定义一个日期类 Date,该类对象存放一个日期,可以提供的操作有: void GetDate(); //取日期值,格式如“2001 年 2 月 5 日” void GetYear(); //取
- Java工作笔记:部署Tomcat时使用jni和jna调用DLL文件的问题