测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A1073. [COCI-2006_2007-contest3]#3 NPUZZLE

编程题 普及/提高-

题目描述

N-puzzle is a puzzle that goes by many names and has many variants. In this problem we will use the 15-puzzle. It consists of a 4-by-4 grid of sliding squares where one square is missing. The squares are labeled with uppercase letters 'A' through 'O', with the desired layout as follows:
A B C D E F G H I J K L M N O .
It can be useful (for example, when solving the puzzle using a computer) to define the "scatter" of a puzzle as the sum of distances between each square's current position and its position in the desired layout. The distance between two squares is their Manhattan distance (the absolute value of the sum of differences between the two rows and the two columns).
Write a program that calculates the scatter of the given puzzle.

输入格式

Four lines of input contain four characters each, representing the state of the puzzle.

输出格式

Output the scatter of the puzzle on a single line.

输入输出样例

输入 #1
ABCD 
EFGH 
IJKL 
M.NO 
输出 #1
2
输入 #2
.BCD 
EAGH 
IJFL 
MNOK
输出 #2
6
上一题 去做题 下一题