编程介的小学生 2017-11-20 15:50 采纳率: 0.2%
浏览 634
已采纳

HDU CakeMan

Problem Description
If you ask one student of HDU “who is the superstar in HDU now?” ,the answer must be “HDU CakeMan” .He sells little cakes in the gate of the HDU students’ dormitory every day .As he says “做人要有小蛋糕精神,不怕风吹雨打,永远三块钱”.But he has no permission. So once seeing ChengGuan coming , he have to run home as fast as possible.

Now , ChengGuan is coming now. After some days investigation,ChengGuan have the map of HDU , and know the home of CakeMan, so can you tell me the minimum time ChengGuan cost to catch CakeMan?

Once seeing ChengGuan coming, CakeMan will run home through a way which cost the least time , if there are more than one ways , he will randomly choose one ,so none knows which way he takes this time.
ChengGuan are be ordered to catch him today, so they want to know the nearest grid which CakeMan will surely pass (excluding the start point of CakeMan and CakeMan’s home).

Input
The first line of input gives the number of cases, T (at most 90).
the first line of each case has four numbers n,m. (2<=n,m<=100)
then n lines with m characters describe the maze
‘D’ represents the init position of CakeMan.
‘S’ represents the position of the home of CakeMan.
‘C’ represents the position of the home of ChengGuan.
‘.’ represents the grids can be walked on.
‘X’ represents the wall which can not be stepped on.
‘A’ A is a integer between 0 and 9, represents the grid stands one HDU student who want A pack of Cake. when CakeMan pass on the grid has a integer on it ,he have to stay A seconds to sell cakes to the students (total costs A + 1 seconds to pass the grid), otherwise he pass the grid in one second. And the data makes sure that there must be at least one way to let CakeMan home.

Output
If there is one nearest grid on the map where ChengGuan can catch CakeMan surely, output how much time(one second one step) can ChengGuan get to this grid.output -1 other wise.

Sample Input
1
4 9
..X..S...
.........
X...123..
D.......C

Sample Output
7

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-09-15 11:49
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀