QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 32 MB مجموع النقاط: 20

#17558. NPUZZLE

الإحصائيات

N-puzzle(N数码问题)有许多不同的称呼和变体。在本题中,我们将使用 15-puzzle(15数码)。它由一个 $4 \times 4$ 的滑动方块网格组成,其中缺少一个方块。方块用大写字母 'A' 到 'O' 标记,目标布局如下:

A B C D
E F G H
I J K L
M N O .

在解决此类谜题时(例如,使用计算机求解时),定义谜题的“散布度”(scatter)会非常有用。散布度定义为每个方块('A' 到 'O')的当前位置与其在目标布局中位置之间的距离之和。两个位置之间的距离为它们的曼哈顿距离(即行差的绝对值与列差的绝对值之和)。

请编写一个程序,计算给定谜题的散布度。

输入格式

输入包含四行,每行四个字符,表示谜题的当前状态。

输出格式

在单行中输出该谜题的散布度。

样例

输入样例 1

ABCD
EFGH
IJKL
M.NO

输出样例 1

2

输入样例 2

.BCD
EAGH
IJFL
MNOK

输出样例 2

6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.