No.228 Yukiko-chan's 15 Puzzle
タグ : / 解いたユーザー数 248
作問者 :
sugim48
Problem Statement
Yukiko-chan is playing a puzzle called the "15 puzzle".
The rules of the 15 puzzle are shown below.
Pieces with the numbers from 1 to 15 written on them are placed in order on a 4×4 board (see the figure below).
You repeatedly slide a piece adjacent to the empty square (above, below, left, or right of it) into the empty square.
You succeed if you can create the target arrangement of pieces.
Yukiko-chan has grown bored of the usual way of playing the 15 puzzle.
So she decided to play with the following new rule added.
Rule: A piece that has been slid once cannot be slid again
Given a target arrangement of pieces, determine whether that arrangement can be created.
Input
$a_{11}$ $a_{12}$ $a_{13}$ $a_{14}$
$a_{21}$ $a_{22}$ $a_{23}$ $a_{24}$
$a_{31}$ $a_{32}$ $a_{33}$ $a_{34}$
$a_{41}$ $a_{42}$ $a_{43}$ $a_{44}$
The target arrangement of pieces is given.
$a_{ij}$ are distinct integers from 0 to 15.
Here, 0 represents the empty square.
For example, the initial arrangement is input as in Sample 1.
Output
Print Yes if the target arrangement of pieces can be created, and No otherwise.
Print a newline at the end.
Sample
Sample 1
Input
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0
Output
Yes
The initial arrangement is itself the target arrangement.
Sample 2
Input
1 2 3 4 5 6 7 8 9 10 12 0 13 14 11 15
Output
Yes
Sample 3
Input
1 2 3 4 5 6 7 8 9 10 12 15 13 14 11 0
Output
No
To create the target arrangement, the piece 15 would have to be slid at least 2 times.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。