编程介的小学生 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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流