HDU 1242
简单题
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std; const int MAX=;
const int inf=;
int tim[MAX][MAX];
char maze[MAX][MAX];
int n,m;
int ai,aj;
typedef struct c{
int i,j,ti;
bool operator <(const c &A)const {
if(ti>A.ti) return true;
return false;
}
}Node;
Node tmp,pushed;
priority_queue<Node>que;
int dir[][]={,,,-,,,-,}; bool ok(int i,int j){
if(i>=&&i<n&&j>=&&j<m&&maze[i][j]!='#')
return true;
return false;
} bool bfs(){
int ti,tj;
while(!que.empty()){
tmp=que.top();
que.pop();
if(maze[tmp.i][tmp.j]=='r'){
printf("%d\n",tmp.ti);
return true;
}
for(int i=;i<;i++){
ti=tmp.i+dir[i][];
tj=tmp.j+dir[i][];
if(ok(ti,tj)){
if(maze[ti][tj]=='.'||maze[ti][tj]=='r'){
if(tmp.ti+<tim[ti][tj]){
tim[ti][tj]=tmp.ti+;
pushed.i=ti; pushed.j=tj; pushed.ti=tmp.ti+;
que.push(pushed);
}
}
else if(maze[ti][tj]=='x'){
if(tmp.ti+<tim[ti][tj]){
tim[ti][tj]=tmp.ti+;
pushed.i=ti; pushed.j=tj; pushed.ti=tmp.ti+;
que.push(pushed);
}
}
}
}
}
return false;
} int main(){
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<n;i++){
scanf("%s",maze[i]);
for(int j=;j<m;j++){
if(maze[i][j]=='a'){
ai=i; aj=j;
}
tim[i][j]=inf;
}
}
tim[ai][aj]=;
tmp.i=ai; tmp.j=aj; tmp.ti=;
que.push(tmp);
if(!bfs()){
printf("Poor ANGEL has to stay in the prison all his life.\n");
}
while(!que.empty())
que.pop();
}
return ;
}
HDU 1242的更多相关文章
- hdu 1242 Rescue
题目链接:hdu 1242 这题也是迷宫类搜索,题意说的是 'a' 表示被拯救的人,'r' 表示搜救者(注意可能有多个),'.' 表示道路(耗费一单位时间通过),'#' 表示墙壁,'x' 代表警卫(耗 ...
- HDU 1242 (BFS搜索+优先队列)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目大意:多个起点到一个终点,普通点耗时1,特殊点耗时2,求到达终点的最少耗时. 解题思路: ...
- hdu - 1242 Rescue && hdu - 2425 Hiking Trip (优先队列+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了 ...
- hdu 1242 Rescue(bfs)
此刻再看优先队列,不像刚接触时的那般迷茫!这也许就是集训的成果吧! 加油!!!优先队列必须要搞定的! 这道题意很简单!自己定义优先级别! +++++++++++++++++++++++++++++++ ...
- 杭电 HDU 1242 Rescue
http://acm.hdu.edu.cn/showproblem.php?pid=1242 问题:牢房里有墙(#),警卫(x)和道路( . ),天使被关在牢房里位置为a,你的位置在r处,杀死一个警卫 ...
- HDU 1242 Rescue(优先队列)
题目来源: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by ...
- HDU 1242 Rescue(BFS+优先队列)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by t ...
- ZOJ-1649 Rescue BFS (HDU 1242)
看题传送门: ZOJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 HDU http://acm.hdu.edu. ...
- HDU 1242 Rescue(BFS),ZOJ 1649
题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...
- F - JDG HDU - 2112 (最短路)&& E - IGNB HDU - 1242 (dfs)
经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬 ...
随机推荐
- 94. Ext.MessageBox消息框
转自:https://www.cnblogs.com/libingql/archive/2012/03/30/2426198.html Ext JS消息提示框主要包括:alert.confirm.pr ...
- XML案例(使用JAXP进行DOM解析)
1.book.xml <?xml version="1.0" encoding="UTF-8" standalone="no"?> ...
- 关于TJOI2014的一道题——Alice and Bob
B Alice and Bob •输入输出文件: alice.in/alice.out •源文件名: alice.cpp/alice.c/alice.pas • 时间限制: 1s 内存限制: 128M ...
- A - Beautiful Matrix
Problem description You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let' ...
- C - Crazy Town
Problem description Crazy Town is a plane on which there are n infinite line roads. Each road is def ...
- input表单(02)
01.表单的代码实现 <!DOCTYPE html> <html> <head> <title>世纪佳缘,你在我也在</title> < ...
- C#获取窗口大小和位置坐标 GetWindowRect用法
[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetWi ...
- ASP.NET MVC5 网站开发实践(一)
一.开发环境 1.开发环境: Visual Studio 2013 2.数据库:Sql Server 2012 3.代码管理:TFS(微软免费提供的) 说明:VS2013与vs2012感觉变化不大,我 ...
- eclipse中导入maven项目:org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.proje
org.codehaus.plexus.archiver.jar.Manifest.write(java.io.PrintWriter) 解决方法为:更新eclipse中的maven插件 1.help ...
- PyCharm 恢复默认设置 | JetBrains IDE 配置文件安装目录
网上的答案为什么都乱七八糟并且全都全篇一律?某度知道是发源地? 先说 Mac 按需运行下面的 rm 删除命令 # Configuration rm -rf ~/Library/Preferences/ ...