Explorer

矫情吗;* 2022-09-19 12:29 264阅读 0赞

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

发表评论

表情:
评论列表 (有 0 条评论,264人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Internet Explorer安全区域

    控制脚本的安全策略,如果设置的太严格将会失去脚本的部分功能,如果设置的太宽松,将会失去安全性。 为了在Internet Explorer浏览器中灵活使用脚本,可以通过安全区域

    相关 Log Explorer使用说明

    操作步骤 下载完在数据库服务器中安装客户端和服务端,然后打开Log Explorer,4.2的界面以蓝色为主调,运行软件可见: (1).点击<Attach Log File