链接:https://acs.jxnu.edu.cn/problem/HDU1026
题目:
描述:
The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castle. The castle is a large labyrinth. To make the problem simply, we assume the labyrinth is a N*M two-dimensional array which left-top corner is (0,0) and right-bottom corner is (N-1,M-1). Ignatius enters at (0,0), and the door to feng5166's room is at (N-1,M-1), that is our target. There are some monsters in the castle, if Ignatius meet them, he has to kill them. Here is some rules:
1.Ignatius can only move in four directions(up, down, left, right), one step per second. A step is defined as follow: if current position is (x,y), after a step, Ignatius can only stand on (x-1,y), (x+1,y), (x,y-1) or (x,y+1).
2.The array is marked with some characters and numbers. We define them like this:
. : The place where Ignatius can walk on.
X : The place is a trap, Ignatius should not walk on it.
n : Here is a monster with n HP(1<=n<=9), if Ignatius walk on it, it takes him n seconds to kill the monster.
Your task is to give out the path which costs minimum seconds for Ignatius to reach target position. You may assume that the start position and the target position will never be a trap, and there will never be a monster at the start position.输入:
The input contains several test cases. Each test case starts with a line contains two numbers N and M(2<=N<=100,2<=M<=100) which indicate the size of the labyrinth. Then a N*M two-dimensional array follows, which describe the whole labyrinth. The input is terminated by the end of file. More details in the Sample Input.
输出:
For each test case, you should output "God please help our poor hero." if Ignatius can't reach the target position, or you should output "It takes n seconds to reach the target position, let me show you the way."(n is the minimum seconds), and tell our hero the whole path. Output a line contains "FINISH" after each test case. If there are more than one path, any one is OK in this problem. More details in the Sample Output.
翻译如下
描述:
公主被魔王feng5166绑架了,我们的勇者Ignatius必须去拯救我们美丽的公主。现在他进入了魔王
feng5166的城堡。魔王的城堡是一个巨大的迷宫。为了简化问题,我们假设迷宫是个N*M的二维数组,其中左上角为(0,0),右下角为(N-1,M-1)。勇者Ignatius初始位置在(0,0),魔王feng5166所在的房间为(N-1,M-1),也就是我们的目标。城堡里有很多怪物,如果勇者Ignatius遭遇了怪物,他将会击杀怪物,但存在以下规则:
1.勇者Ignatius每秒只能向四个方向移动一格(上、下、左、右)。移动的规则:如果当前位置是(x,y),那么在移动后,勇者Ignatius只能站在(x-1,y), (x+1,y), (x,y-1)或着(x,y+1)。
2.该数组包含一些字母或者数字。我们这样定义它们:
“ . ” :勇者Ignatius可以进入的格子。
“ X ”:这个格子是个陷阱,勇者Ignatius不应该进入该格。
“ n ”:这是一个拥有n血量的怪物(1<=n<=9),如果勇者Ignatius走在上面,他需要n秒才能击杀这个怪物。
你的任务是算出勇者Ignatius到达目标位置所需的最短时间。题目保证起始位置和目标位置不会是一个陷阱,起始位置不会出现怪物。
输入:
输入包含多组样例。每组样例第一行包含两个整数N和M(2<=N<=100,2<=M<=100),表示迷宫的规格。接下来是一个N*M的二维数组,表示迷宫的具体情况。输入直到文件末尾停止。更多细节请参照样例输入。
输出:
对于每组样例,如果勇者Ignatius无法抵达目标格子,输出"God please help our poor hero.",否则输出"It takes n seconds to reach the target position, let me show you the way.",其中n为最短时间。之后告诉我们的勇者Ignatius如何到达目标格子。每组样例后面应当输出一行"FINISH"。如果方法不止一种,如何一种方法都是可以的。更多细节请参照样例输出。
本文介绍了一道关于勇者Ignatius解救公主的编程题,要求计算他在带有陷阱和怪物的迷宫中到达目标位置的最短路径。输入描述了迷宫布局和规则,输出包括可能的时间和路径指导。

335

被折叠的 条评论
为什么被折叠?



