题解

题目大意 给一个图S是起点 T是终点 .是空房间 #是毒气室 B是氧气瓶存放室 P是加速室
每次走到空房间或者起点消耗1秒 走到氧气室获得一个氧气瓶最多携带5个氧气瓶 进入毒气室需要一瓶氧气并且消耗2秒 进入加速室不消耗时间(可以这么理解) 问S走到T的最短时间

按照题意 分层BFS搜索即可

AC代码

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;const int INF = 0x3f3f3f3f;
const int MAXN = 110;
int n, m;
int dir[4][2] = { -1, 0, 1, 0, 0, -1, 0, 1 };
char g[MAXN][MAXN];
int vis[10][MAXN][MAXN];struct node
{int y, x, c, k;bool operator < (const node &oth) const{return this->c > oth.c;}
};
int BFS(int y, int x)
{priority_queue<node> pq;pq.push({ y, x, 0, 0 });while (!pq.empty()){y = pq.top().y, x = pq.top().x;int c = pq.top().c, k = pq.top().k;pq.pop();if (vis[k][y][x])continue;vis[k][y][x] = 1;for (int i = 0; i < 4; i++){int xx = x + dir[i][1], yy = y + dir[i][0];if (yy < 1 || yy > n || xx < 1 || xx > m)continue;if (g[yy][xx] == 'T')return c + 1;else if (g[yy][xx] == '.' || g[yy][xx] == 'S')pq.push({yy, xx, c + 1, k});else if (g[yy][xx] == '#' && k)pq.push({ yy, xx, c + 2, k - 1});else if (g[yy][xx] == 'B')pq.push({ yy, xx, c + 1, min(5, k + 1) });else if (g[yy][xx] == 'P')pq.push({ yy, xx, c, k });}}return -1;
}
int main()
{
#ifdef LOCALfreopen("C:/input.txt", "r", stdin);
#endifwhile (cin >> n >> m, n && m){memset(vis, 0, sizeof(vis));memset(g, 0, sizeof(g));int x, y;for (int i = 1; i <= n; i++){scanf("%s", g[i] + 1);for (int j = 1; j <= m; j++)if (g[i][j] == 'S')x = j, y = i;}int res = BFS(y, x);printf("%d\n", res);}return 0;
}

ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A. Saving Tang Monk II相关推荐

  1. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A Saving Tang Monk II【分层bfs】

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 <Journey to the West>(also <Monkey>) is one of the ...

  2. hihoCoder-1828 2018亚洲区预选赛北京赛站网络赛 A.Saving Tang Monk II BFS

    题面 题意:N*M的网格图里,有起点S,终点T,然后有'.'表示一般房间,'#'表示毒气房间,进入毒气房间要消耗一个氧气瓶,而且要多停留一分钟,'B'表示放氧气瓶的房间,每次进入可以获得一个氧气瓶,最 ...

  3. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 【bfs + 记忆化搜索 + 剪枝】 AC 代码

    ACM 北京区域赛 bfs+剪枝+ms 第一个一遍过的题目,基本没有看题解 记忆搜索当中,注意初始化成一个特殊值:而在访问之后,每个点就会有一个不同于INF(或者 -1等特殊标记)的值 先到先得,适者 ...

  4. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 Tomb Raider(map+二进制枚举)

    #1829 : Tomb Raider 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Lara Croft, the fiercely independent daugh ...

  5. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days(双向队列+尺取法)

    #1831 : 80 Days 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 80 Days is an interesting game based on Jules ...

  6. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 D【队列】

    #1831 : 80 Days 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 80 Days is an interesting game based on Jules ...

  7. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 D. 80 Days

    题解 题目大意 n个点组成一个环形 初始钱为m 从i走到j需要-b[i] + a[j] 要求按照顺时针走完所有的点(不用再回到起点) 过程中m不能小于0 输出最小的起点编号 直接把a[i]和b[i]合 ...

  8. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛

    Saving Tang Monk II Tomb Raider Cheat 80 Days Odd Chess Shortest Path Problem The Mole K-Dimensional ...

  9. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days ——尺取

    描述 80 Days is an interesting game based on Jules Verne's science fiction "Around the World in E ...

最新文章

  1. 【Sql Server】DateBase-视频总结
  2. 城市轨道交通运营票务管理论文_【专业简介】城市轨道交通运营与管理
  3. 《你必须掌握的Entity Framework 6.x与Core 2.0》书籍出版
  4. Stack Overflow 上人气最旺的 10 个 Java 问题
  5. 【英语学习】【WOTD】tenacious 释义/词源/示例
  6. ping .............
  7. 超56万5G用户重返4G:用户难以接受这两点
  8. 单体内置对象_单体内置对象
  9. Cacti实现网络监控的使用心得(1)
  10. jQuery中调用方法,动态拼接传字符串参数格式
  11. 关于amd cpu超频 个人心得
  12. RecyclerView加载多类型item 实现淘宝首页布局
  13. FAST-LIO2.0代码解析(二)preprocess.cpp
  14. wps中有半根横线无法选中无法删除
  15. Handlebars.js入门教程
  16. 360度全景的地拍如何制作?
  17. 安装服务器的win pe系统教程,u盘pe安装win7系统教程图解
  18. Revit出图翻模【局部三维功能】,三维视图从此不卡
  19. 数字调制系列:IQ调制基本理论
  20. 西北乱跑娃 --- bottle web框架技术讨论

热门文章

  1. flv,wmv等视频格式加速播放方法
  2. 晋江文学城、番茄小说和米读小说被约谈 要求停更整改
  3. 算法训练营 重编码_编码训练营手册:沉浸式工程程序介绍
  4. onload 和 onunload 事件
  5. 蓝桥云课 Python新手入门课 笔记
  6. 全面解读亚马逊云科技 Private 5G 的革新理念
  7. 【Xilinx DDS】Vivado代码实现FPGA DDS
  8. Infiniband vs 以太网Ethernet 对比
  9. c语言程序的模板,C++中模板与用C语言中实现模板
  10. 2015最新iherb海淘攻略-图文新手教程