2022.2.11

题目网址:

http://noi.openjudge.cn/ch0205/8436/

原题:

Saving Tang Monk

总时间限制:

1000ms

内存限制:

65536kB

描述

《Journey to theWest》(also 《Monkey》) is one of the Four Great Classical Novelsof Chinese literature. It was writtenby Wu Cheng'en during the Ming Dynasty. In this novel, Monkey King Sun Wukong,pig Zhu Bajie and Sha Wujing, escorted Tang Monk to India to getsacred Buddhism texts.

During thejourney, Tang Monk was often captured by demons. Most of demons wanted to eatTang Monk to achieve immortality, but some female demons just wanted to marryhim because he was handsome. So, fighting demons and saving Monk Tang is themajor job for Sun Wukong to do.

Once, TangMonk was captured by the demon White Bones. White Bones lived in a palace andshe cuffed Tang Monk in a room. Sun Wukong managed to get into the palace. Butto rescue Tang Monk, Sun Wukong might need to get some keys and kill somesnakes in his way.

The palace can be described as a matrix of characters. Each characterstands for a room. In the matrix, 'K' represents the original position of SunWukong, 'T' represents the location of Tang Monk and 'S' stands for a room witha snakein it. Please note that there are only one 'K' and one 'T', and at mostfive snakesin the palace. And, '.' means a clear room as well '#' means a deadlyroom which Sun Wukong couldn't get in.

There may be some keys of different kinds scattered in the rooms, butthere is at most one key in one room. There are at most 9 kinds of keys. A roomwith a key in it is represented by a digit(from '1' to '9'). For example, '1'means a room with a first kind key, '2' means a room with a second kind key,'3' means a room with a third kind key... etc. To save Tang Monk, Sun Wukongmust get ALL kinds of keys(in other words, at least one key for each kind).

For each step, Sun Wukong couldmove to the adjacent rooms(except deadly rooms) in 4 directions(north, west, southand east), and each step took him one minute. If he entered a room in which aliving snakestayed, he must kill the snake.Killing a snakealso took one minute. If Sun Wukong entered a room where there is a keyof kind N, Sun would get that key if and only if he had already got keys ofkind 1,kind 2 ... and kind N-1. In other words, Sun Wukong must get a key ofkind N before he could get a key of kind N+1 (N>=1). If Sun Wukong got allkeys he needed and entered the room in which Tang Monk was cuffed, the rescue mission is completed. If Sun Wukong didn't get enough keys,he still could pass through Tang Monk's room. Since Sun Wukong was a impatient monkey,he wanted to save Tang Monk as quickly as possible. Please figure out theminimum time Sun Wukong needed to rescue Tang Monk.

输入

There are several test cases.
For each case, the first line includes two integers N and M(0 < N <= 100, 0<=M<=9), meaning that the palace is a N×N matrix and Sun Wukong needed M kinds of keys(kind 1, kind 2, ... kind M).
Then the N×N matrix follows.
The input ends with N = 0 and M = 0.

输出

For each test case, print the minimum time (in minutes) Sun Wukong needed to save Tang Monk. If it's impossible for Sun Wukong to complete the mission, print "impossible"(no quotes).

翻译:

描述:

《西游记》(也叫《齐天大圣》)是中国文学的四大经典小说之一。它在明朝由吴承恩著作。在这个小说里,齐天大圣孙悟空,猪八戒,沙悟净,护送唐僧去印度取经。

在旅途期间,唐僧经常被妖魔鬼怪捕获。大多数妖魔鬼怪想吃唐僧以实现长生不老,但是一些女性妖魔鬼怪只是想要嫁给他,因为他很英俊。所以,与妖魔鬼怪搏斗以及拯救唐僧是孙悟空的主要任务。

有一次,唐僧被妖怪白骨精抓到了。白骨精住在一个宫殿里面并且把唐僧拷在一个房间里面。孙悟空设法成功进入这个宫殿。为了拯救唐僧,孙悟空可能需要拿到某些钥匙并且杀了一些在路上的蛇。

这个宫殿可以被描述为一个字符矩阵。每个字符代表一个房间。在这个矩阵中,‘K’代表孙悟空最初的位置。‘T’代表唐僧的位置,‘S’代表有一条蛇在里面。请注意这里只有一个‘K’和一个‘T’,这个宫殿里最多5条蛇。‘.’代表一个干净的房间,‘#’代表一个孙悟空不能进去的死寂的房间。

这里可能有一些钥匙散布在房间里,但是这里一个房间最多有一把钥匙。这里最多有9种钥匙。有一把钥匙的一个房间由一个数字表示(从‘1’到‘9’)。例如,‘1’意味着一个有一把第一种钥匙的房间,‘2’意味着一个有一把第二种钥匙的房间,‘3’意味着一个有一把第三种钥匙的房间...等等。为了拯救唐僧,孙悟空必须拿到所有的钥匙(换言之,每种钥匙至少拿到一把)。

对于每一步,孙悟空可以往东西南北四个方向走进房间(死寂房间除外),每一步都要花费一分钟。如果他进入了一个有蛇的房间,那么他必须杀死这条蛇。杀死一条蛇也需要花费一分钟。如果孙悟空进入了一个有钥匙的房间,并且他已经拿到了第1,2,...,n-1种钥匙,他将拿到这把钥匙。换言之,在孙悟空拿到第N+1把钥匙之前,他必须拿到N种钥匙种每种一把(N>1)。如果孙悟空拿到了他所有需要的钥匙并且进入了唐僧被拷的那个房间,那么救援任务就完成了。如果孙悟空没有拿到足够的钥匙,他仍然能通过唐僧的房间。因为孙悟空是一个没有耐心的猴子,所以他想尽可能快的拯救唐僧。请找到孙悟空需要救唐僧的最短时间。

输入:

这里有几组测试样例。

对于每一组样例,第一行包含两个整数N和M(0<N<=100,0<=M<=9),代表这个宫殿是一个N*N的矩阵,孙悟空需要M种钥匙(第一种,第二种,...第M种)。

接下来有一个N*N的矩阵。

输入以N=0和M=0结束。

输出:

对于每组测试样例,打印出孙悟空需要救出唐僧的最短时间(以分钟为单位)。如果孙悟空不可能完成这个任务,那么打印“impossible”(不带引号)。

Saving Tang Monk(翻译)相关推荐

  1. HDU 5025:Saving Tang Monk(BFS + 状压)

    http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description <Journey to t ...

  2. HDU 5025 Saving Tang Monk(广州网络赛D题)

    HDU 5025 Saving Tang Monk 题目链接 思路:记忆化广搜,vis[x][y][k][s]表示在x, y结点,有k把钥匙了,蛇剩余状态为s的步数,先把图预处理出来,然后进行广搜即可 ...

  3. Saving Tang Monk II HihoCoder - 1828(2018北京网络赛三维标记+bfs)

    <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chines ...

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

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

  5. #hihoCoder #1828 : Saving Tang Monk II (分层BFS)

    描述 <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chi ...

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

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

  7. HihoCoder - 1828 Saving Tang Monk II(bfs+动态规划/bfs+优先队列)

    题目链接:点击查看 题目大意:孙悟空要走迷宫去救唐僧,给出n和m约束迷宫大小: 迷宫中: S代表起点 T代表终点 B代表氧气区,经过可以获得一罐氧气,最多储存5罐氧气 #代表毒气区,经过需要花费2个时 ...

  8. 2014 网选 广州赛区 hdu 5025 Saving Tang Monk(bfs+四维数组记录状态)

    1 /* 2 这是我做过的一道新类型的搜索题!从来没想过用四维数组记录状态! 3 以前做过的都是用二维的!自己的四维还是太狭隘了..... 4 5 题意:悟空救师傅 ! 在救师父之前要先把所有的钥匙找 ...

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

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

  10. 2018年 ICPC北京网络预选赛 A题 Saving Tang Monk II

    由于个人比较菜啊,这道题错了4次才ac,思路是对的,就是各种死在细节上. 题目大意:唐僧给妖精抓走了,悟空要去救出唐僧,给你一个地图长N高M,'S'表示悟空所在地,'T' 表示唐僧所在地,'.'i表示 ...

最新文章

  1. G41显卡Linux驱动,Intel最新G41/G43/G45集成显卡驱动下载
  2. linux按函数数字大小排序,linux awk 数组排序多种实现方法
  3. 01_反射_02_反射类的构造方法
  4. 揭秘ASP.NET 2.0的Eval方法
  5. IaaS、PaaS、SaaS
  6. 如何在右键新建中添加新建xmind文件
  7. 通过自定义函数计算阶乘
  8. 每个人都会有的第一次
  9. Qwerty Learner:为键盘工作者设计的单词记忆与英语肌肉记忆锻炼网页
  10. 互联网产品之运营管理
  11. 使用Tensorflow2和Pytorch实现线性回归
  12. 操作系统实践-BIOS
  13. memcache数据组织
  14. (转)案例分析:中介提供的二手房合同不规范催生大量房屋买卖纠纷
  15. 图书推荐:SQL Server 2012 T-SQL基础教程 Itzik Ben-Gan
  16. python解析雷达数据_激光雷达数据解析(Python-lidar-data-analysis_V1.0)
  17. 2020.1.16 Java数组基础
  18. es集群健康值变为黄色解决办法
  19. android 菜单展开动画,FloatingActionButton实现 展开/折叠 的多级悬浮菜单
  20. Windows扩展屏开发总结

热门文章

  1. android Studio导出的apk解析包时出错
  2. 0/1背包问题 - 回溯法(C++实现)
  3. javascript中的深拷贝和浅拷贝!!!!!
  4. 文件夹加密文件以便保护数据点不了,怎么办?
  5. Allnbsp;Younbsp;Willnbsp;Nevernbsp;Know
  6. 雅思词汇之万词plan:第8-365天
  7. static、final、private关键字的使用?
  8. TF-IDF介绍及Python实现文本聚类
  9. n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位
  10. HDU-1018(n!的位数)