3-Puzzle
시간 제한1초메모리 제한2048 MB
1부터 3까지의 타일과 빈칸 하나가 있는 2x2 슬라이딩 퍼즐이 주어질 때, 완성 상태까지 필요한 최소 이동 횟수를 구한다.
문제
Your friend needs help solving a -Puzzle, so to warm up, you solve the -Puzzle instead. A -Puzzle consists of a grid containing tiles numbered through and one empty space. The goal is to slide the tiles around so that they are in ascending row-major order and the empty space is on the bottom right like this:
Given the starting position of a -Puzzle, find the minimum number of moves it takes to solve the puzzle. Here's an example of how sample input can be solved in moves:
Starting position:
After move:
After moves:
After moves:
입력
The input will consist of exactly lines, each containing exactly characters.
Each character is either a number through (representing one of the tiles) or a dash (-) (the empty space).
The puzzle state represented by the input is guaranteed to be a solvable configuration.
출력
Output a singe integer, indicating the minimum number of moves required to solve the puzzle from the provided starting position, or if it's already in the solved position.