杭电 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 ...
随机推荐
- HOOK API(四)—— 进程防终止
HOOK API(四) —— 进程防终止 0x00 前言 这算是一个实战吧,做的一个应用需要实现进程的防终止保护,查了相关资料后决定用HOOK API的方式实现.起初学习HOOK API ...
- UVa1583 Digit Generator
#include <stdio.h> int main(){ int T, N, i, k, digitsum, generator; scanf("%d" ...
- Maven Spring JUnit 在Maven Clean Install时报
问题: Maven Clean Install时, 遇到报错package org.junit does not exist 明显, Unit Test在Compile阶段就被检查了. 而POM.xm ...
- python之math模块
1.math简介 >>>import math #导入math模块 >>>dir(math) #这句可查看所有函数名列表 >>>help(math ...
- 向ibus-table-wubi里添加属于自己的输入法(98五笔)
写在前面: 第三步整理每行的结构相对来说算是最难的,我的方法是先用文本编码转换专家将文本编码转换成utf-8无BOM(linux下有转换命令不会用,一定要是无BOM否则会在linux下打开乱码),再用 ...
- 24_Core Data Demo
今天开始学习Core Data,类似于数据库,可以永久保存数据.不过当把App从iPhone删掉之后就没有了.可以用来保存App的运行数据. 参考链接:iOS Swift教程 Core Data 概述 ...
- 【蓝桥杯】入门训练 Fibonacci数列
入门训练 Fibonacci数列 时间限制:1.0s 内存限制:256.0MB 问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. ...
- Android中的一些基础知识(三)
最近在回顾Android的基础知识,就把一些常见的知识点整理一下,以后忘了也可以翻出来看一看. 在TextView中显示图像(使用< img>标签) 在TextView中显示图片的方法有许 ...
- VisualSVN Server安装后,TortoiseSVN远程无法访问版本库。
修正!重演了一遍,发现总结有误,重新整理下.首先访问版本库的路径不清楚的话可以在VisualSVN Server的版本库上右键“Copy URL to Clipboard”.访问版本库失败的几种情况: ...
- Redis初始化配置及增删改查
package com.calc.tools import redis.clients.jedis.JedisPool import redis.clients.jedis.Jedis import ...