题意 求迷宫中从a的位置到r的位置须要的最少时间  经过'.'方格须要1s  经过‘x’方格须要两秒  '#'表示墙

因为有1s和2s两种情况  须要在基础迷宫bfs上加些推断

令到达每一个点的时间初始为无穷大  当从一个点到达该点用的时间比他本来的时间小时  更新这个点的时间并将这个点入队  扫描全然图就得到答案咯

#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; const int N = 205;
char mat[N][N];
int time[N][N], sx, sy;
int dx[4] = {0, 0, -1, 1};
int dy[4] = { -1, 1, 0, 0};
struct grid
{
int x, y;
grid(int xx = 0, int yy = 0): x(xx), y(yy) {}
}; void bfs()
{
memset(time, 0x3f, sizeof(time));
time[sx][sy] = 0;
queue<grid> g;
g.push(grid(sx, sy)); while(!g.empty())
{
grid cur = g.front();
g.pop();
int cx = cur.x, cy = cur.y, ct = time[cx][cy];
for(int i = 0; i < 4; ++i)
{
int nx = cx + dx[i], ny = cy + dy[i];
if(mat[nx][ny] && mat[nx][ny] != '#')
{
int tt = ct + 1;
if(mat[cx][cy] == 'x') ++tt;
if(tt < time[nx][ny])
{
time[nx][ny] = tt;
g.push(grid(nx, ny));
}
}
}
}
} int main()
{
int n, m, ex, ey;
while (~scanf("%d%d", &n, &m))
{
memset(mat, 0, sizeof(mat));
for(int i = 1; i <= n; ++i)
scanf("%s", mat[i] + 1);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
if(mat[i][j] == 'a') sx = i, sy = j;
else if(mat[i][j] == 'r') ex = i, ey = j;
bfs();
if(time[ex][ey] != time[0][0])
printf("%d\n", time[ex][ey]);
else
printf("Poor ANGEL has to stay in the prison all his life.\n");
} return 0;
}

ZOJ 1649 Rescue(有敌人迷宫BFS)的更多相关文章

  1. zoj 1649 Rescue (BFS)(转载)

    又是类似骑士拯救公主,不过这个是朋友拯救天使的故事... 不同的是,天使有多个朋友,而骑士一般单枪匹马比较帅~ 求到达天使的最短时间,杀死一个护卫1 units time , 走一个格子 1 unit ...

  2. zoj 1649 Rescue

    BFS..第一次使用C++ STL的队列来写广搜. #include<stdio.h> #include<string.h> #include<math.h> #i ...

  3. BFS zoj 1649

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 //hnldyhy(303882171) 11:12:46 // z ...

  4. ZOJ 1649:Rescue(BFS)

    Rescue Time Limit: 2 Seconds      Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put ...

  5. HDU 1242 Rescue(BFS),ZOJ 1649

    题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...

  6. ZOJ 649 Rescue(优先队列+bfs)

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  7. zoj 1649 bfs

    Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M ...

  8. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  9. poj 1383 Labyrinth【迷宫bfs+树的直径】

    Labyrinth Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 4004   Accepted: 1504 Descrip ...

随机推荐

  1. TCP排查常用命令

    1.查看TCP连接状态命令 netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,"\t" ...

  2. Oracle 批量插入值

    工作中常遇到将Excel文档数据转为SQL语句,然后再将SQL语句插入到数据库已完成数据转移保存到数据库中,下面介绍下如何一次性插入多条SQL语句,先抛个图: 由于真实数据不变给大家看,所以这里是做了 ...

  3. vue 中数据没有同步渲染的解决方法

    今天在做一个页面,遇到一个数据渲染不同步的问题,如下: 代码如下:原理:点击时,对应的banklist 的选项选项变为 true 选中状态 html: <div class="PayO ...

  4. invoke与call

    “调用一个委托实例” 中的 “调用” 对应的是invoke,理解为 “唤出” 更恰当.它和后面的 “在一个对象上调用方法” 中的 “调用” 稍有不同,后则对应的是call.在英语的语境中,invoke ...

  5. 5.29clone项目地址

  6. Asp.net MVC4 Step By Step(4)-使用Ajax

    Ajax技术就是利用Javascript和XML技术实现这样的效果, 可以向Web服务器发送异步请求, 返回更新部分页面的数据, 而不需要全部更新整个页面. Ajax请求两种类型的内容, 一种是服务端 ...

  7. 三维重建:SFM中BA的并行化

    1. BA在重建中的作用 借鉴于运动中重建的方法,BA引入SLAM过程,而传统的滤波方法引入BA是跟随闭环检测出现. 1.1 BA在滤波方法中的嵌入 PTAM 1.2 BA在闭环检测之后的应用 在三维 ...

  8. OpenCV:OpenCV目标检测Adaboost+haar源代码分析

    使用OpenCV作图像检测, Adaboost+haar决策过程,其中一部分源代码如下: 函数调用堆栈的底层为: 1.使用有序决策桩进行预测 template<class FEval> i ...

  9. (转)OpenLayers3基础教程——OL3 介绍interaction

    http://blog.csdn.net/gisshixisheng/article/details/46808647 概述: 本节主要讲述OL3的交互操作interaction,重点介绍draw,s ...

  10. 身份认证防止重放攻击的challenge-response方法

    或者叫询问-应答机制. 基于挑战/应答(Challenge/Response)方式的身份认证系统就是每次认证时认证服务器端都给客户端发送一个不同的"挑战"字串,客户端程序收到这个& ...