编程介的小学生 2017-11-20 15:50 采纳率: 20.5%
浏览 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 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊