302455: CF472E. Design Tutorial: Learn from a Game

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Design Tutorial: Learn from a Game

题目描述

One way to create task is to learn from game. You should pick a game and focus on part of the mechanic of that game, then it might be a good task. Let's have a try. Puzzle and Dragon was a popular game in Japan, we focus on the puzzle part of that game, it is a tile-matching puzzle. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF472E/0df1f37c391cc1320e82fbc238d35e416c16ae44.png)(Picture from Wikipedia page: http://en.wikipedia.org/wiki/Puzzle_&_Dragons)There is an $ n×m $ board which consists of orbs. During the game you can do the following move. In the beginning of move you touch a cell of the board, then you can move your finger to one of the adjacent cells (a cell not on the boundary has 8 adjacent cells), then you can move your finger from the current cell to one of the adjacent cells one more time, and so on. Each time you move your finger from a cell to another cell, the orbs in these cells swap with each other. In other words whatever move you make, the orb in the cell you are touching never changes. The goal is to achieve such kind of pattern that the orbs will be cancelled and your monster will attack the enemy, but we don't care about these details. Instead, we will give you the initial board as an input and the target board as an output. Your goal is to determine whether there is a way to reach the target in a single move.

输入输出格式

输入格式


One way to create task is to learn from game. You should pick a game and focus on part of the mechanic of that game, then it might be a good task. Let's have a try. Puzzle and Dragon was a popular game in Japan, we focus on the puzzle part of that game, it is a tile-matching puzzle. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF472E/0df1f37c391cc1320e82fbc238d35e416c16ae44.png)(Picture from Wikipedia page: http://en.wikipedia.org/wiki/Puzzle_&_Dragons)There is an $ n×m $ board which consists of orbs. During the game you can do the following move. In the beginning of move you touch a cell of the board, then you can move your finger to one of the adjacent cells (a cell not on the boundary has 8 adjacent cells), then you can move your finger from the current cell to one of the adjacent cells one more time, and so on. Each time you move your finger from a cell to another cell, the orbs in these cells swap with each other. In other words whatever move you make, the orb in the cell you are touching never changes. The goal is to achieve such kind of pattern that the orbs will be cancelled and your monster will attack the enemy, but we don't care about these details. Instead, we will give you the initial board as an input and the target board as an output. Your goal is to determine whether there is a way to reach the target in a single move.

输出格式


One way to create task is to learn from game. You should pick a game and focus on part of the mechanic of that game, then it might be a good task. Let's have a try. Puzzle and Dragon was a popular game in Japan, we focus on the puzzle part of that game, it is a tile-matching puzzle. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF472E/0df1f37c391cc1320e82fbc238d35e416c16ae44.png)(Picture from Wikipedia page: http://en.wikipedia.org/wiki/Puzzle_&_Dragons)There is an $ n×m $ board which consists of orbs. During the game you can do the following move. In the beginning of move you touch a cell of the board, then you can move your finger to one of the adjacent cells (a cell not on the boundary has 8 adjacent cells), then you can move your finger from the current cell to one of the adjacent cells one more time, and so on. Each time you move your finger from a cell to another cell, the orbs in these cells swap with each other. In other words whatever move you make, the orb in the cell you are touching never changes. The goal is to achieve such kind of pattern that the orbs will be cancelled and your monster will attack the enemy, but we don't care about these details. Instead, we will give you the initial board as an input and the target board as an output. Your goal is to determine whether there is a way to reach the target in a single move.

输入输出样例

输入样例 #1

2 2
1 3
2 3
1 3
3 2

输出样例 #1

3
1 1
2 2
2 1
1 1

输入样例 #2

2 2
1 3
2 3
1 2
2 3

输出样例 #2

-1

输入样例 #3

1 4
1 2 3 4
4 3 2 1

输出样例 #3

-1

输入样例 #4

4 1
1
2
3
4
3
1
2
4

输出样例 #4

2
3 1
2 1
1 1

Input

题意翻译

给定 $n \times m$ 的初始矩阵和目标矩阵,你可以进行下面**一次**操作: 选择一个格子,然后与相邻的格子(八联通)交换,可以看作选定的权值移动到这个格子,接着可以继续移动选定的权值到其他相邻格子。 问是否有解,使得起始矩阵变为目标矩阵。 #### 输入格式 第一行两个整数 $n,m(1 \le n,m \le 30)$。 接下来 $n \times m$ 为起始矩阵。 接下来 $n \times m$ 为目标矩阵。 矩阵值域在 $1 \le s_{i,j} \le 900$。 #### 输出格式 无解输出 $-1$。 否则第一行输出一个整数 $k\ (1 \le k \le 10^6)$,代表移动次数。 接下来 $1$ 行两个整数 $x,y$,代表选定的起始点。 接下来 $k-1$ 行每行两个整数 $x,y$,代表移动到的位置。

加入题单

上一题 下一题 算法标签: