A12068 | Three Pieces
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$ , but it still is $N \times N$ . Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are pairwise distinct. The $j$ -th square in the $i$ -th row has a number $A_{ij}$ written on it.
In your chess set you have only three pieces: a knight, a bishop and a rook. At first, you put one of them on the square with the number $1$ (you can choose which one). Then you want to reach square $2$ (possibly passing through some other squares in process), then square $3$ and so on until you reach square $N^2$ . In one step you are allowed to either make a valid move with the current piece or replace it with some other piece. Each square can be visited arbitrary number of times.
A knight can move to a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. A bishop moves diagonally. A rook moves horizontally or vertically. The move should be performed to a different square from the one a piece is currently standing on.
You want to minimize the number of steps of the whole traversal. Among all the paths to have the same number of steps you want to choose the one with the lowest number of piece replacements.
What is the path you should take to satisfy all conditions?
In your chess set you have only three pieces: a knight, a bishop and a rook. At first, you put one of them on the square with the number $1$ (you can choose which one). Then you want to reach square $2$ (possibly passing through some other squares in process), then square $3$ and so on until you reach square $N^2$ . In one step you are allowed to either make a valid move with the current piece or replace it with some other piece. Each square can be visited arbitrary number of times.
A knight can move to a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. A bishop moves diagonally. A rook moves horizontally or vertically. The move should be performed to a different square from the one a piece is currently standing on.
You want to minimize the number of steps of the whole traversal. Among all the paths to have the same number of steps you want to choose the one with the lowest number of piece replacements.
What is the path you should take to satisfy all conditions?
输入格式
The first line contains a single integer $N$ ( $3 \le N \le 10$ ) — the size of the chessboard.
Each of the next $N$ lines contains $N$ integers $A_{i1}, A_{i2}, \dots, A_{iN}$ ( $1 \le A_{ij} \le N^2$ ) — the numbers written on the squares of the $i$ -th row of the board.
It is guaranteed that all $A_{ij}$ are pairwise distinct.
Each of the next $N$ lines contains $N$ integers $A_{i1}, A_{i2}, \dots, A_{iN}$ ( $1 \le A_{ij} \le N^2$ ) — the numbers written on the squares of the $i$ -th row of the board.
It is guaranteed that all $A_{ij}$ are pairwise distinct.
输出格式
The only line should contain two integers — the number of steps in the best answer and the number of replacement moves in it.
输入输出样例
输入 #1
3 1 9 3 8 6 7 4 2 5
输出 #1
12 1
Here are the steps for the first example (the starting piece is a knight):
1. Move to $(3, 2)$
2. Move to $(1, 3)$
3. Move to $(3, 2)$
4. Replace the knight with a rook
5. Move to $(3, 1)$
6. Move to $(3, 3)$
7. Move to $(3, 2)$
8. Move to $(2, 2)$
9. Move to $(2, 3)$
10. Move to $(2, 1)$
11. Move to $(1, 1)$
12. Move to $(1, 2)$
1. Move to $(3, 2)$
2. Move to $(1, 3)$
3. Move to $(3, 2)$
4. Replace the knight with a rook
5. Move to $(3, 1)$
6. Move to $(3, 3)$
7. Move to $(3, 2)$
8. Move to $(2, 2)$
9. Move to $(2, 3)$
10. Move to $(2, 1)$
11. Move to $(1, 1)$
12. Move to $(1, 2)$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted