杭电 HDU 1242 Rescue
http://acm.hdu.edu.cn/showproblem.php?pid=1242
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring> #define MAX 999999 using namespace std; struct Node
{
int x,y;
int time;
}; char map[210][210];
int st[210][210];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int n,m,mintime; void Bfs(Node p)
{
Node now,next;
queue<Node> q;
int i;
q.push(p);
while(!q.empty())
{
now = q.front();
q.pop();
if(now.time >= mintime) //剪枝,超过最短时间的不用再走了
{
break;
}
if(map[now.x][now.y] == 'a') //找到天使时更新最短步骤
{
if(now.time < mintime)
{
mintime = now.time;
}
}
if(map[now.x][now.y] == 'x') //如果当前为门卫则多花1秒来杀死他
{
now.time += 1;
}
st[now.x][now.y] = 2; //标记此路径已经到达
next.time = now.time + 1; //下一步的时间加一
for(i = 0; i < 4; i++)
{
next.x = now.x + dir[i][0];
next.y = now.y + dir[i][1];
if(map[next.x][next.y] != '#' && st[next.x][next.y] == 0)
{
st[next.x][next.y] = 1; //标记此路径已经入队
q.push(next);
}
}
}
return ;
} int main()
{
int i,j;
Node now;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(map,'#',sizeof(map)); //初始化全为墙
memset(st,0,sizeof(st)); //初始化所有路径均未走过
mintime = MAX;
for(i = 1; i <= n; i++)
{
for(j = 1; j <= m; j++)
{
cin >> map[i][j];
if(map[i][j] == 'r')
{
now.x = i;
now.y = j;
now.time = 0;
}
}
}
Bfs(now);
if(mintime == MAX)
{
printf("Poor ANGEL has to stay in the prison all his life.\n");
}
else
{
printf("%d\n",mintime);
}
} return 0;
}
杭电 HDU 1242 Rescue的更多相关文章
- hdu 1242 Rescue
题目链接:hdu 1242 这题也是迷宫类搜索,题意说的是 'a' 表示被拯救的人,'r' 表示搜救者(注意可能有多个),'.' 表示道路(耗费一单位时间通过),'#' 表示墙壁,'x' 代表警卫(耗 ...
- 杭电 HDU ACM 2795 Billboard(线段树伪装版)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 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 题目描述: 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 ...
- HDU 1242 -Rescue (双向BFS)&&( BFS+优先队列)
题目链接:Rescue 进度落下的太多了,哎╮(╯▽╰)╭,渣渣我总是埋怨进度比别人慢...为什么不试着改变一下捏.... 開始以为是水题,想敲一下练手的,后来发现并非一个简单的搜索题,BFS做肯定出 ...
- hdu 1242:Rescue(BFS广搜 + 优先队列)
Rescue Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- HDU 1242 Rescue (BFS(广度优先搜索))
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
随机推荐
- DataSet - DataTable - DataRow 读取 xml 文件 + 搜索
DataSet ds = XmlHelper.GetDataSetByXml(AppDomain.CurrentDomain.BaseDirectory + "/Config/ConfigN ...
- SQL Server 2012学习笔记 1 命令行安装
setup.exe /Q /IACCEPTSQLSERVERLICENSETERMS /ACTION=install /PID=748RB-X4T6B-MRM7V-RTVFF-CHC8H /FEATU ...
- c#软件工程师笔试题
近来有打算重新找工作,还没提离职,投了几家公司简历,其中一家比较中意的公司给发了面试题,其实,好像是好几天前的事了,主要是Gmail邮箱很少用,所以一直都没去看,今天看到题目给解了. 题目如下: 题目 ...
- BZOJ 2821: 作诗(Poetize)( 分块 )
分块,分成N^0.5块.O(N^1.5)预处理出sm[i][j]表示前i块中j的出现次数, ans[i][j]表示第i~j块的答案. 然后就可以O(N^0.5)回答询问了.总复杂度O((N+Q)N^0 ...
- Lucence.net索引技术 一
1.建立索引 为了对文档进行索引,Lucene 提供了五个基础的类,他们分别是 Document, Field, IndexWriter, Analyzer, Directory.下面我们分别介绍一下 ...
- (转)WIN2003服务器禁PING的方法
方法一:用windows系统自带的防火墙规则设置禁止别人Ping我的机器 win2003系统默认情况下,所有Internet控制消息协议(ICMP)选项均被禁用,也就是对客户机有反应,因而易于受到攻击 ...
- PHP练习项目笔记之COOKIES
主要是在登录和退出的时候,设置cookies.来保存登录和安全退出 1:在登录页面设置 //设置cookies的值 _setcookies($_rows['tg_username'], $_rows[ ...
- libcprops
Install Howto Download the latest epel-release rpm from http://dl.fedoraproject.org/pub/epel/6/x86_6 ...
- Matplotlib中文乱码
想要分析一批数据,画出图形会比较直观.所以就搜索了一下各种软件,最终选择使用python的matplotlib.原因也是因为python使用起来比较方便,虽然R才是分析数据的首选,不过,没有R的基础, ...
- contains 和 ele.compareDocumentPosition确定html节点间的关系
~~~ nodeA.contains(nodeB) //ie , nodeA.compareDocumentPosition(nodeB) //firefox opera 1.DOMElement ...