Explorer

 
Explorer
作者:Ackarlix
Input file: explorer.in
In a faraway land, there lives an explorer who devotes himself to exploration.  His dream is to find priceless treasures one day, but the unfortunate man has not ever found a small piece of diamond throughout most of his life.  But now, he realizes that maybe his dream would come true recently, because he has got a map on which it is said to have recorded the place of some invaluable treasures.  The treasures’ history could be traced back to remote antiquity, and the treasures were so mysterious that no one could tell what it is definitely.  The explorer was excited at first, but later, facing the precious map, he got disheartened.  Although the map is detailed, he is not sure whether he is able to reach the destination and finally get back to the starting point.  So he asks you to write a program to give him an answer.  If you tell him that he could reach the destination and return the jumping-off point, he will start his exploration.  But if the answer is that he couldn’t get there and then go back, the plan of the exploration will be canceled.
The map which the explorer shows is very large, and it is divided into partitions of 20 km´20 km.  The explorer also knows that he happen to cover 20 km a day, that is, he could walk from one partition to the left, right, upper or down adjoining one.  For some reasons, his route must be horizontal or vertical, that means he couldn’t go to the upper-left, upper-right, down-left, or down-right partition forthrightly.  The whole map consists of the following terrains: desert, oasis, forest, city, road, and marsh.  Obviously, the writer of the map is kindhearted, in the map, he even tell how much water would be cost in the every kind of terrain.  When you walk on road, you will have to consume water of 2 kg a day.  When you pace in forest, the consumption will be 1 kg, because the plants will shield you from the sunshine.  And when you go through oasis, it is fortunate that you needn’t use any water you carry about, since you could find enough water to satisfy your thirsty.  If you travel in desert, the amount of the water will be rise to 4 kg.  For an explorer, it is quite lucky to arrive at a city, because the hospitable inhabitants will supply him as much water as he may carry about.  But if you happen to approach a marsh, you should be careful, because it will bring the angel of death to anyone who dares to make an exploration in it.  The explorer is unwilling to take such a risk, so a marsh means an unreachable place to him.  During his journey, if the amount of the water he holds decrease to 0, he will be unable to go on his journey.
Before showing you the map, the explorer had made some modifications on it.  He marked the point of departure as S, the treasure-storing place as T, deserts as D, oases as O, forests as F, cities as C, roads as R, and marshes as M. So the map will become a sketch as follows:
RRRRRRRRRRRRRRR
RRSRRRFFFFFFFFF
DDDDDDDDFFFFFFF
DDDDODDDFFFFFFF
DDDDDDCDFFFFFFF
DTDDOOOOFFFFFFF
RRRRRRRRRRRRRMM
As far as the terrains of the starting point and the treasure-storing point are concerned, they may be regarded the same as that of the road.  That is, while going to the treasure-storing place, the explorer will consume 2 kg water at the starting point; while going back, the explorer will consume the same amount of water at the treasure-storing place.  You may assume that to unearth the treasure will not take much time, so that it won’t consume any additional water.
The explorer will tell you the limitation of the amount of water he can carry about.  As it should be, he will carry as much water as possible.  So you are required to give him the answer whether he may start his exploration.  If the plan isn’t canceled, you should also tell him the maximum amount of water he will hold when he come back to the starting point.  He has enough time to perform the exploration, so that what he is interested in is the amount of the remainder water instead of the time to be spent.  However, he is as cunning as a fox, in order not to let you know the exact place, he will show you many maps, so you should make decisions one after another.
Note: When the amount of water the explorer holds decrease to 0, if the explorer stays in city, he may go on his adventure, because he will be supplied enough water;  if he is in an oasis, he may go to the adjoining oases (if there are oases adjoin to it), because walking in oases doesn’t consume any water he holds;  but if he is walking in other terrains, he must give up his adventure.
Input
The input file describes several test cases, each of which describes a treasure map.  The first line of input for each test case contains a non-negative single integer w, the amount of water that the explorer may carry about.  The next line contains a pair of integers m, n (0 £ m, n £ 1000), giving the dimensions of the treasure map in 20 km partitions.  Immediately following are m lines of n characters, giving the description of terrains on the map that the explorer shows you, including a character “S”, the starting point, and a character “T”, the destination.
The input is terminated by a description starting with w = 0.  This description should not be processed.
Output
For each treasure map, display the map number (starting with 1).  Then, if the explorer is able to reach the destination and safely come back, display the answer “Yes”, following the maximum amount of water he will hold.  If the plan is canceled, display the answer “No”.  There should be a blank line between treasure maps.

Sample Input
100
15 7
RRRRRRRRRRRRRRR
RRSRRRFFFFFFFFF
DDDDDDDDFFFFFFF
DDDDODDDFFFFFFF
DDDDDDCDFFFFFFF
DTDDOOOOFFFFFFF
RRRRRRRRRRRRRMM
5
15 7
RRRRRRRRRRRRRRR
RRSRRRFFFFFFFFF
DDDDDDDDFFFFFFF
DDDDODDDFFFFFFF
DDDDDDCDFFFFFFF
DTDDOOOOFFFFFFF
RRRRRRRRRRRRRMM
0
Output for the Sample Input
Map #1
Yes
The maximum amount of the remainder water is 88
 
Map #2
No
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值