hdu1242 Rescue(BFS +优先队列 or BFS ) (二)

2014-11-23 22:37:19 ? 作者: ? 浏览: 10
s = q.front(); q.pop(); if(map[s.x][s.y] == 'a') { cout << s.step << endl; prove =1; } //如取出的是在有警卫的格子中,即杀掉警卫再次进入队列 if(map[s.x][s.y] == 'x') { map[s.x][s.y] = '.'; s.step += 1; q.push(s); continue; } for(int i = 0; i < 4; i++) { e.x = s.x + dx[i]; e.y = s.y + dy[i]; if(!check(e.x, e.y) || visit[e.x][e.y] || map[e.x][e.y] == '#') continue; e.step = s.step + 1; q.push(e); visit[e.x][e.y] = 1; } } } int main() { while(cin >> N >> M) { for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) { cin >> map[i][j]; if(map[i][j] == 'r') { sx = i; sy = j; } } prove = 0; BFS(); if(!prove) cout << "Poor ANGEL has to stay in the prison all his life." << endl; } return 0; }

-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: