A12059 | Colored Cubes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya passes all exams! Despite expectations, Vasya is not tired, moreover, he is ready for new challenges. However, he does not want to work too hard on difficult problems.
Vasya remembered that he has a not-so-hard puzzle: $m$ colored cubes are placed on a chessboard of size $n \times n$ . The fact is that $m \leq n$ and all cubes have distinct colors. Each cube occupies exactly one cell. Also, there is a designated cell for each cube on the board, the puzzle is to place each cube on its place. The cubes are fragile, so in one operation you only can move one cube onto one of four neighboring by side cells, if only it is empty. Vasya wants to be careful, so each operation takes exactly one second.
Vasya used to train hard for VK Cup Final, so he can focus his attention on the puzzle for at most $3$ hours, that is $10800$ seconds. Help Vasya find such a sequence of operations that all cubes will be moved onto their designated places, and Vasya won't lose his attention.
Vasya remembered that he has a not-so-hard puzzle: $m$ colored cubes are placed on a chessboard of size $n \times n$ . The fact is that $m \leq n$ and all cubes have distinct colors. Each cube occupies exactly one cell. Also, there is a designated cell for each cube on the board, the puzzle is to place each cube on its place. The cubes are fragile, so in one operation you only can move one cube onto one of four neighboring by side cells, if only it is empty. Vasya wants to be careful, so each operation takes exactly one second.
Vasya used to train hard for VK Cup Final, so he can focus his attention on the puzzle for at most $3$ hours, that is $10800$ seconds. Help Vasya find such a sequence of operations that all cubes will be moved onto their designated places, and Vasya won't lose his attention.
输入格式
The first line contains two integers $n$ and $m$ ( $1 \leq m \leq n \leq 50$ ).
Each of the next $m$ lines contains two integers $x_i$ , $y_i$ ( $1 \leq x_i, y_i \leq n$ ), the initial positions of the cubes.
The next $m$ lines describe the designated places for the cubes in the same format and order.
It is guaranteed that all initial positions are distinct and all designated places are distinct, however, it is possible that some initial positions coincide with some final positions.
Each of the next $m$ lines contains two integers $x_i$ , $y_i$ ( $1 \leq x_i, y_i \leq n$ ), the initial positions of the cubes.
The next $m$ lines describe the designated places for the cubes in the same format and order.
It is guaranteed that all initial positions are distinct and all designated places are distinct, however, it is possible that some initial positions coincide with some final positions.
输出格式
In the first line print a single integer $k$ ( $0 \le k \leq 10800$ ) — the number of operations Vasya should make.
In each of the next $k$ lines you should describe one operation: print four integers $x_1$ , $y_1$ , $x_2$ , $y_2$ , where $x_1, y_1$ is the position of the cube Vasya should move, and $x_2, y_2$ is the new position of the cube. The cells $x_1, y_1$ and $x_2, y_2$ should have a common side, the cell $x_2, y_2$ should be empty before the operation.
We can show that there always exists at least one solution. If there are multiple solutions, print any of them.
In each of the next $k$ lines you should describe one operation: print four integers $x_1$ , $y_1$ , $x_2$ , $y_2$ , where $x_1, y_1$ is the position of the cube Vasya should move, and $x_2, y_2$ is the new position of the cube. The cells $x_1, y_1$ and $x_2, y_2$ should have a common side, the cell $x_2, y_2$ should be empty before the operation.
We can show that there always exists at least one solution. If there are multiple solutions, print any of them.
输入输出样例
输入 #1
2 1 1 1 2 2
输出 #1
2 1 1 1 2 1 2 2 2
输入 #2
2 2 1 1 2 2 1 2 2 1
输出 #2
2 2 2 2 1 1 1 1 2
输入 #3
2 2 2 1 2 2 2 2 2 1
输出 #3
4 2 1 1 1 2 2 2 1 1 1 1 2 1 2 2 2
输入 #4
4 3 2 2 2 3 3 3 3 2 2 2 2 3
输出 #4
9 2 2 1 2 1 2 1 1 2 3 2 2 3 3 2 3 2 2 1 2 1 1 2 1 2 1 3 1 3 1 3 2 1 2 2 2
In the fourth example the printed sequence of movements (shown on the picture below) is valid, but not shortest. There is a solution in $3$ operations.


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted