|
||||||||||
Three KingdomsTime 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 . ¡®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
Sample Output
Author jwq Source | ||||||||||
|