ACM Ignatius and the Princess I

公主被BEelzebub feng5166绑架,我们的英雄Ignatius必须拯救我们美丽的公主。 现在他进入feng5166的城堡。城堡是一个大迷宫。为简单起见,( To make the problem simply, )我们假设迷宫是一个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 HP(1 <= n <= 9)的怪物,如果Ignatius走在上面,则需要他n秒才能杀死怪物。
您的任务是发出Ignatius到达目标位置的最小秒数的路径。你可以假设起始位置和目标位置永远不会成为陷阱,在起始位置永远不会有怪物。

Input

该输入包含几个测试用例。每个测试用例以包含两个数字N和M(2 <= N <= 100,2 <= M <= 100)的行开始,表示迷宫的大小。然后是一个N * M二维阵列,它描述了整个迷宫。输入结束文件结束。样品输入中的更多细节。
Output

对于每个测试用例,如果Ignatius不能达到目标位置,你应该输出 "God please help our poor hero."  或者你应该输出"It takes n seconds to reach the target position, let me show you the way."(n is the minimum seconds), 告诉我们的英雄的整个路径。在每个测试用例之后输出一行包含“FINISH”。 如果有不止一个路径,任何一个都可以在这个问题。样品输出中的更多细节。

Sample Input

5 6
.XX.1.
..X.2.
2...X.
...XX.
XXXXX.
5 6
.XX.1.
..X.2.
2...X.
...XX.
XXXXX1
5 6
.XX...
..XX1.
2...X.
...XX.
XXXXX.

Sample Output

It takes 13 seconds to reach the target position, let me show you the way.
1s:(0,0)->(1,0)
2s:(1,0)->(1,1)
3s:(1,1)->(2,1)
4s:(2,1)->(2,2)
5s:(2,2)->(2,3)
6s:(2,3)->(1,3)
7s:(1,3)->(1,4)
8s:FIGHT AT (1,4)
9s:FIGHT AT (1,4)
10s:(1,4)->(1,5)
11s:(1,5)->(2,5)
12s:(2,5)->(3,5)
13s:(3,5)->(4,5)
FINISH
It takes 14 seconds to reach the target position, let me show you the way.
1s:(0,0)->(1,0)
2s:(1,0)->(1,1)
3s:(1,1)->(2,1)
4s:(2,1)->(2,2)
5s:(2,2)->(2,3)
6s:(2,3)->(1,3)
7s:(1,3)->(1,4)
8s:FIGHT AT (1,4)
9s:FIGHT AT (1,4)
10s:(1,4)->(1,5)
11s:(1,5)->(2,5)
12s:(2,5)->(3,5)
13s:(3,5)->(4,5)
14s:FIGHT AT (4,5)
FINISH
God please help our poor hero.
FINISH
时间: 2024-11-03 21:58:19

ACM Ignatius and the Princess I的相关文章

[ACM] hdu 1029 Ignatius and the Princess IV (动归或hash)

笨蛋的难题(一) 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述        笨蛋之所以称为笨蛋,是因为他有点路痴.他一旦不高兴,就必然一个人漫无目的的出去走走.今天下雨了,他又不高兴了,怎么办?那就出去走呗,这不又丢了,这次幸好记下出来时的方向,并且在一张纸上密密麻麻的记下了他拐的弯(他很聪明吧,拐的弯都是90度的弯),0代表左拐,1代表右拐,那么多0.1,他实在看不下去了,正好遇见善良加聪明的你,你能告诉他,他现在面向哪吗? 输入 多组测试数据 第一行 输入:

hdu acm 1028 数字拆分Ignatius and the Princess III

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11810    Accepted Submission(s): 8362 Problem Description "Well, it seems the first problem is too easy. I will let

ACM学习历程—HDU1028 Ignatius and the Princess(组合数学)

Ignatius and the Princess Description "Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.        "The second problem is, given an positive integer N, we define an equation like this:

ACM: HDU 1028 Ignatius and the Princess III-DP

HDU 1028 Ignatius and the Princess III Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description "Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says. &qu

杭电 HDU ACM 1028 Ignatius and the Princess III

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14870    Accepted Submission(s): 10469 Problem Description "Well, it seems the first problem is too easy. I will le

(全排列)Ignatius and the Princess II -- HDU -- 1027

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5822    Accepted Submission(s): 3433 Problem Description Now our h

HDU 1027 Ignatius and the Princess II

原题代号:HDU 1027 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1027 原题描述: Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8415    Accepted Submission(s): 4955 Problem

杭电 1029 Ignatius and the Princess IV

http://acm.hdu.edu.cn/showproblem.php?pid=1029 Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others) Total Submission(s): 16754    Accepted Submission(s): 6730 Problem Description "OK, you ar

hdu 1028 Ignatius and the Princess III(母函数,完全背包)

http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分问题. 第一道母函数...母函数入门 小于等于n的整数共有n个,1,2......n,每个数都有无限多个,对于整数1,它所对应的母函数为(1+x+x^2+...+x^k+...),整数2对应的母函数为(1+x^2+X^4+...+x^(2*k)+...),整数3对应的母函数为(1+x^3+x^6+...+x^(3*k)+...),以此类推,直到整数n. 那么n的整数划分的个数就是这n个母函数乘积