题意 求迷宫中从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. Comet反向ajax技术实现客服聊天系统

    说明:Comet反向Ajax是在看了燕十八老师的视频以后,结合他讲解的例子,自己用ajax+java实现了一遍.在这里把代码贴出来,以供大家学习.同时,ajax轮询技术也可以用在消息推送的功能中,下次 ...

  2. android service--delphixe 10.3

    开发中的陷阱: 1. 别放什么 *.wav文件,这个 服务窗口不能随便放东西,不然铁定出现意想不到的结果,比如 无法运行,因为没 ui界面,随意都不知是啥问题. 2. 不能加载 datamodule ...

  3. NYOJ999 师傅又被妖怪抓走了

    只记得当下的眼疼 , ok 各种数据也试了 , 就是 他娘的不对 , 我也是醉了 . 也是日了最野的狗 附上日了哮天犬的代码 , 这个题 先放放, 一段时间后再试试 , 明天开始状态压缩吧 .为期两天 ...

  4. MySQL数据库中的delete语句

    在MySQL数据库中,只有在数据存在的情况下删除,才会返回受影响的行数.比如大于0的数,如果删除了不存在的数据,则会返回0:

  5. HTML学习(2018.1.18)

    1,         转义字符 转义字符:用于表示网页中的特殊字符 XHTML不直接输入符号,建议使用转义字符. &nbsp------空格: &copy------版权: & ...

  6. (转)Vue 爬坑之路(一)—— 使用 vue-cli 搭建项目

    vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue-cli 可以快速创建 vue 项目,GitHub地址是:https://github.com/vuejs/vue-cli 一. ...

  7. Emmet(Zen Coding)语法规则简介

    ———Emmet(Zen Coding)语法规则简介——— [Zen Coding可谓快速开发HTML和CSS的利器,主要采用仿css类选择器方式编写代码,以下是该利器的基本语法规则和代码示例] 基础 ...

  8. dubbo之异步调用

    异步调用 基于 NIO 的非阻塞实现并行调用,客户端不需要启动多线程即可完成并行调用多个远程服务,相对多线程开销较小. 在 consumer.xml 中配置: <dubbo:reference ...

  9. 分布式机器学习框架:MxNet 前言

           原文连接:MxNet和Caffe之间有什么优缺点一.前言: Minerva: 高效灵活的并行深度学习引擎 不同于cxxnet追求极致速度和易用性,Minerva则提供了一个高效灵活的平台 ...

  10. pycharm主题 变量颜色 自定义

    File--Settings--Edtior--Color Schame-- Lanuage Defaults