我是靠谱客的博主 魔幻板凳,这篇文章主要介绍Rescue(简单搜索题),现在分享给大家,希望可以做个参考。

一看就知道和1026是一样的,并且比1026更简单!除了延迟处理,不含任何技巧!和我一样水平的银,赶紧练练手吧。。。TT。。http://acm.hdu.edu.cn/showproblem.php?pid=1242

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream> #include <cstdio> #include <string.h> #include <queue> #define N 201 using namespace std; int n,m,res,s,e; int jump[4][2]={{1,0},{-1,0},{0,1},{0,-1}}; char map[N][N]; bool f[N][N]; struct node { int x,y,s; }q,r,p; void init() { int i,j; res=-1; for(i=0;i<n;i++) { getchar(); for(j=0;j<m;j++) { cin>>map[i][j]; if(map[i][j]=='r') { s=i;e=j; } } } memset(f,0,sizeof(f)); /*for(i=0;i<n;i++) { for(j=0;j<n;j++) cout<<map[i][j]; cout<<endl; }*/ } int is_b(node p) { if(p.x<0 || p.y<0 || p.x>=n || p.y>=m || f[p.x][p.y] || map[p.x][p.y]=='#') return 1; return 0; } void bfs() { queue< node > que; q.x=s;q.y=e;q.s=0; f[s][e]=1; que.push(q); while(!que.empty()) { q=que.front();que.pop(); if(map[q.x][q.y]=='a') { res=q.s; return; } if(map[q.x][q.y]=='x') { ++q.s; map[q.x][q.y]='.'; que.push(q); } else { for(int i=0;i<4;i++) { p.x=q.x+jump[i][0]; p.y=q.y+jump[i][1]; p.s=q.s+1; if(is_b(p)) continue; f[p.x][p.y]=1; que.push(p); } } } } int main () { //freopen("j.txt","r",stdin); while(cin>>n>>m) { init(); bfs(); if(res!=-1) cout<<res<<endl; else cout<<"Poor ANGEL has to stay in the prison all his life."<<endl; } return 0; }



最后

以上就是魔幻板凳最近收集整理的关于Rescue(简单搜索题)的全部内容,更多相关Rescue(简单搜索题)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部