A9257 | Bombs
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains $n$ bombs, the $i$ -th bomb is at point with coordinates $(x_{i},y_{i})$ . We know that no two bombs are at the same point and that no bomb is at point with coordinates $(0,0)$ . Initially, the robot is at point with coordinates $(0,0)$ . Also, let's mark the robot's current position as $(x,y)$ . In order to destroy all the bombs, the robot can perform three types of operations:
1. Operation has format "1 k dir". To perform the operation robot have to move in direction $dir$ $k$ ( $k>=1$ ) times. There are only $4$ directions the robot can move in: "R", "L", "U", "D". During one move the robot can move from the current point to one of following points: $(x+1,y)$ , $(x-1,y)$ , $(x,y+1)$ , $(x,y-1)$ (corresponding to directions). It is forbidden to move from point $(x,y)$ , if at least one point on the path (besides the destination point) contains a bomb.
2. Operation has format "2". To perform the operation robot have to pick a bomb at point $(x,y)$ and put it in a special container. Thus, the robot can carry the bomb from any point to any other point. The operation cannot be performed if point $(x,y)$ has no bomb. It is forbidden to pick a bomb if the robot already has a bomb in its container.
3. Operation has format "3". To perform the operation robot have to take a bomb out of the container and destroy it. You are allowed to perform this operation only if the robot is at point $(0,0)$ . It is forbidden to perform the operation if the container has no bomb.
Help the robot and find the shortest possible sequence of operations he can perform to destroy all bombs on the coordinate plane.
1. Operation has format "1 k dir". To perform the operation robot have to move in direction $dir$ $k$ ( $k>=1$ ) times. There are only $4$ directions the robot can move in: "R", "L", "U", "D". During one move the robot can move from the current point to one of following points: $(x+1,y)$ , $(x-1,y)$ , $(x,y+1)$ , $(x,y-1)$ (corresponding to directions). It is forbidden to move from point $(x,y)$ , if at least one point on the path (besides the destination point) contains a bomb.
2. Operation has format "2". To perform the operation robot have to pick a bomb at point $(x,y)$ and put it in a special container. Thus, the robot can carry the bomb from any point to any other point. The operation cannot be performed if point $(x,y)$ has no bomb. It is forbidden to pick a bomb if the robot already has a bomb in its container.
3. Operation has format "3". To perform the operation robot have to take a bomb out of the container and destroy it. You are allowed to perform this operation only if the robot is at point $(0,0)$ . It is forbidden to perform the operation if the container has no bomb.
Help the robot and find the shortest possible sequence of operations he can perform to destroy all bombs on the coordinate plane.
输入格式
The first line contains a single integer $n$ ( $1<=n<=10^{5}$ ) — the number of bombs on the coordinate plane. Next $n$ lines contain two integers each. The $i$ -th line contains numbers $(x_{i},y_{i})$ ( $-10^{9}<=x_{i},y_{i}<=10^{9}$ ) — the coordinates of the $i$ -th bomb. It is guaranteed that no two bombs are located at the same point and no bomb is at point $(0,0)$ .
输出格式
In a single line print a single integer $k$ — the minimum number of operations needed to destroy all bombs. On the next lines print the descriptions of these $k$ operations. If there are multiple sequences, you can print any of them. It is guaranteed that there is the solution where $k<=10^{6}$ .
输入输出样例
输入 #1
2 1 1 -1 -1
输出 #1
12 1 1 R 1 1 U 2 1 1 L 1 1 D 3 1 1 L 1 1 D 2 1 1 R 1 1 U 3
输入 #2
3 5 0 0 5 1 0
输出 #2
12 1 1 R 2 1 1 L 3 1 5 R 2 1 5 L 3 1 5 U 2 1 5 D 3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted