F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Three Kingdoms

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1475    Accepted Submission(s): 558


Problem Description
Three Kingdoms is a funny game. Often Liu Bei is weak and has to run away,so in the game Liu Bei has a skill called "Dunzou". This time you are playing the role of Liu Bei.As Cao Cao's power is so strong, there is nothing you can do but escaping. Please select an optimal path to achieve the purpose .
To simplify the problem, Liu Bei can only move in one of the four direction (up, down,right,left) each time. The map contains the following characters:
¡®A¡¯ : Representative of watchtower, which has an attack range of 2(measured by Manhattan distance),and an attack damage of 1.
¡®B¡¯ : Representative of Fort, which has an attack range of 3(measured by Manhattan distance),and an attack damage of 2.
¡®C¡¯ : Representative of Flame, which has an attack damage of 3 to those who step onto it.
¡®D¡¯ : Representative of Archer, which has anattack range of 2(measured by Manhattan distance), and an attack damage of 4.
¡®E¡¯ : Representative of Ordinary soldier, which has anattack range of 1(measured by Manhattan distance), and an attack damage of 5.
¡®$¡¯ : Representative of Liu Bei.
¡®!¡¯ : Representative of Destination.
'#' : Representative of obstacles
¡®.¡¯ : Representative of floor.
Liu Bei can not enter watchtower, forts, Archers, ordinary soldiers,But he can step onto flame or floor.
Some important rules you should note:
1.  Liu Bei will not be hurt by the same thing twice.For example,if Liu Bei has been hurt by one watchtower before,then he step into the attack range of some watchtower later,he will not be hurt.
2.  When Liu Bei reach the destination,you should first judge the attack damage at the destination then finish the game.
3.  You needn¡¯t judge the attack damage at the start position.
Please choose a path which LiuBei would cost the least HP.
 

Input
In the first line there is an integer T, indicates the number of test cases.(T<=60)
In each case,the first line of the input contains two integer n,m(1<=n,m<=50),reperesenting the size of map(n*m).Then follow n lines,each line contain m characters.
There may be some blank lines between each case.
 

Output
For each test case , output ¡°Case d: ¡° where d is the case number counted from one.If Liu Bei can reach the destination then output the minimum HP LiuBei may lose, otherwise output -1.
 

Sample Input
1 4 3 .$. ACB ACB .!.
 

Sample Output
Case 1: 6
 

Author
jwq
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 09:26:19, Gzip enabled