810 - A Dicey Problem

The three-by-three array in Figure 1 is amaze. A standard six-sided die is needed to traverse the maze (the layout of astandard six--sided die is shown in Figure 2). Each maze has an initialposition and an initial die configuration. In Figure 1, the starting positionis row 1, column 2--the ``2'' in the top row of the maze--and the initial dieconfiguration has the ``5'' on top of the die and the ``1'' facing the player(assume the player is viewing the maze from the bottom edge of the figure).


To move through the maze you must tip the die over on an edge to land on anadjacent square, effecting horizontal or vertical movement from one square toanother. However, you can only move onto a square that contains the same numberas the number displayed on the top of the die before the move, or onto a``wild'' square which contains a star. Movement onto a wild square is alwaysallowed regardless of the number currently displayed on the top of the die. Thegoal of the maze is to move the die off the starting square and to then find away back to that same square.


For example, at the beginning of the maze there are two possible moves. Sincethe 5 is on top of the die, it is possible to move down one square, and sincethe square to the left of the starting position is wild it is also possible tomove left. If the first move chosen is to move down, this brings the 6 to thetop of the die and moves are now possible both to the right and down. If thefirst move chosen is instead to the left, this brings the 3 to the top of thedie and no further moves are possible.


If we consider maze locations as ordered pairs of row and column numbers( rowcolumn) with row indexes startingat 1 for the top row and increasing toward the bottom, and column indexesstarting at 1 for the left column and increasing to the right, the solution tothis simple example maze can be specified as: (1,2), (2,2), (2,3), (3,3),(3,2), (3,1), (2,1), (1,1), (1,2). A bit more challenging example maze is shownin Figure 3.


The goal of this problem is to write a program to solve dice mazes. The inputfile will contain several mazes for which the program should search forsolutions. Each maze will have either a unique solution or no solution at all.That is, each maze in the input may or may not have a solution. For each inputmaze, either a solution or a message indicating no solution is possible will besent to the output.

Input 

The input file begins with a linecontaining a string of no more than 20 non-blank characters that names thefirst maze. The next line contains six integers delimited by single spaces.These integers are, in order, the number of rows in the maze (an integer from 1to 10, call this value R), the number of columns in the maze(an integer from 1 to 10, call this valueC), the starting row,the starting column, the number that should be on top of the die at thestarting position, and finally the number that should be facing you on the dieat the starting position. The next R linescontain C integers each, again delimited by singlespaces. ThisR×C array of integers defines themaze. A value of zero indicates an empty location in the maze (such as the twoempty squares in the center column of the maze in Figure 3), and a value of`-1' indicates a wild square. This input sequence is repeated for each maze inthe input. An input line containing only the word `END' (without the quotes) asthe name of the maze marks the end of the input.

Output 

The output should contain the name of eachmaze followed by its solution or the string `No Solution Possible' (without thequotes). All lines in the output file except for the maze names should beindented exactly two spaces. Maze names should start in the leftmost column.Solutions should be output as a comma-delimited sequence of the consecutivepositions traversed in the solution, starting and ending with the same square(the starting square as specified in the input). Positions should be specifiedas ordered pairs enclosed in parentheses. The solution should list 9 positionsper line (with the exception of the last line of the solution for which theremay not be a full 9 positions to list), and no spaces should be present withinor between positions.

SampleInput 

DICEMAZE1

3 3 1 2 5 1

-1 2 4

5 5 6

6 -1 -1

DICEMAZE2

4 7 2 6 3 6

6 4 6 0 2 6 4

1 2 -1 5 3 6 1

5 3 4 5 6 4 2

4 1 2 0 3 -1 6

DICEMAZE3

3 3 1 1 2 4

2 2 3

4 5 6

-1 -1 -1

END

SampleOutput 

DICEMAZE1

 (1,2),(2,2),(2,3),(3,3),(3,2),(3,1),(2,1),(1,1),(1,2)

DICEMAZE2

 (2,6),(2,5),(2,4),(2,3),(2,2),(3,2),(4,2),(4,1),(3,1),

 (2,1),(2,2),(2,3),(2,4),(2,5),(1,5),(1,6),(1,7),(2,7),

 (3,7),(4,7),(4,6),(3,6),(2,6)

DICEMAZE3

  NoSolution Possible

 


Miguel Revilla 2002-06-25

 

500i�00` $��8>Sample Output  

Case 1: still liveafter 100 transitions

Places withtokens: 1 (1)

 

Case 2: dead after9 transitions

Places withtokens: 2 (1)

 

Case 3: still liveafter 1 transitions

Places withtokens: 2 (1) 3 (1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值