ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Ad-Hoc > задача:


50505 - kht Puzzle

Гость
• Вопросы к жюри (1)

Задачи раздела

• 50393 - Palindromic Numbers
• 50396 - Cinema Tickets - 1
• 50325 - How much time passed?
• 50366 - Student Averages (2 Grades)
• 50406 - Draw Pattern 178
• 50416 - Placing Dominoes on Chess...
• 50477 - Character Pyramids
• 50498 - K-Means
• 50505 - kht Puzzle
• 50346 - The Biggest Date
• 50512 - Coding redundancy
• 50528 - Rock-Scissors-Paper
• 50493 - n-digit kth Prime Number
• 50520 - Filling a Matrix Randomly
• 50357 - Convert Euros into Dollars
• 50355 - Bills of City Water Company
• 50454 - What day is it?

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/10000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Question by Ibrahim Mesecan.

kht Puzzle

In 8-Puzzle, you are given a square frame puzzle which consists of 8 numbered tiles and one missing tile. By shifting the tiles to the empty tile position, you are asked to put the numbers in proper order. Your professor is developing a program to solve this problem automatically. For this, he wants a program which solves kth puzzle problem for k between 3 and 7. But solving big puzzles takes too much time so he decided to limit the search process. For that, he wants to search at most 15 steps to decide when k is 3 or 4, and at most 12 steps when 5 ≤ k ≤ 7.

Question: Write a program that reads a matrix configuration. And then, it finds if there is a solution within the given steps length.

Input specification
In the first line, you will be given an integer (n) where 3 ≤ n ≤ 7. Then, in the following n lines you will be given n integers where each number is between 0 and n2-1 And, zero (0) represents the position of the empty tile.

Output specification
If there is a solution show the number of minimum steps. Show -1 (minus 1), if there is no solution within the defined limits (max number of steps given).

Sample Input I
3
4 1 2
7 5 3
8 0 6
Sample Output I
7

Explanation First, you move 8 to the position of 0, then 7 and 4 are moved down, etc.



Для отправки решений необходимо выполнить вход.

www.contester.ru