Lisp / Scheme とかとか@wiki
最終更新:
shigezo
-
view
■ブロック 問題
The Blocks Problem
訳)
n 個のブロックが一列あり、番地が0~n-1で与えられている。さらに5つの命令がある。
n 個のブロックが一列あり、番地が0~n-1で与えられている。さらに5つの命令がある。
- move a onto b
- a, b は数値。 a と b の上に存在する全てのブロックを最初の位置に戻し、a を b の上に載せる。
- move a over b
- a, b は数値。 a の上に存在する全てのブロックを最初の位置に戻し、a を b の一番上に載せる。
- pile a onto b
- a, b は数値。 b の上に存在する全てのブロックを最初の位置に戻し、a と a の上にある全てのブロックを b の上に載せる。
- pile a over b
- a, b は数値。 b の一番上に a と a の上にある全てのブロックを載せる。
- quit
- ブロックの操作を終了する。
※ a ≠ b で、 a と b は同じ番地には存在しないものとする。また全ての不正な命令は無視できる。
■入力
0 < n < 25 と 上記のコマンド
0 < n < 25 と 上記のコマンド
■出力
番地: ブロック郡
番地: ブロック郡
■サンプル
入力 10
move 9 onto 1
move 8 over 1
move 7 over 1
move 6 over 1
pile 8 over 6
pile 8 over 5
move 2 over 1
move 4 over 9
quit
入力 10
move 9 onto 1
move 8 over 1
move 7 over 1
move 6 over 1
pile 8 over 6
pile 8 over 5
move 2 over 1
move 4 over 9
quit
出力
0: 0
1: 1 9 2 4
2:
3: 3
4:
5: 5 8 7 6
6:
7:
8:
9:
0: 0
1: 1 9 2 4
2:
3: 3
4:
5: 5 8 7 6
6:
7:
8:
9: