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 (xi, yi). 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:

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.
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.
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.

Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of bombs on the coordinate plane. Next n lines contain two integers each. The i-th line contains numbers (xi, yi) ( - 109 ≤ xi, yi ≤ 109) — 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).

Output
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 ≤ 106.

Examples
Input
2
1 1
-1 -1
Output
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
Input
3
5 0
0 5
1 0
Output
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

题意: 4种方向模拟,拆炸弹
思路: 先取距离自己曼哈顿距离最近的,排个序就可以实现。然后直接按照距离模拟了

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn = 1e6 + 7;struct node
{int x,y;
}bomb[maxn];
int cmp(node a,node b)
{return (abs(a.x) + abs(a.y)) < (abs(b.x) + abs(b.y));
}
int main(int argc, char *argv[])
{int n;scanf("%d",&n);int ans = 0;for(int i = 0;i < n;i++){scanf("%d %d",&bomb[i].x,&bomb[i].y);if(bomb[i].x == 0){ans-=2;}if(bomb[i].y == 0){ans-=2;}ans += 6;}sort(bomb,bomb + n,cmp);printf("%d\n",ans);for(int i = 0;i < n;i++){int X = -1,Y = -1;if(bomb[i].x > 0){printf("1 %d R\n",bomb[i].x);X = 1;}else if(bomb[i].x < 0){printf("1 %d L\n",abs(bomb[i].x));X = 2;}if(bomb[i].y > 0){printf("1 %d U\n",bomb[i].y);Y = 1;}else if(bomb[i].y < 0){printf("1 %d D\n",abs(bomb[i].y));Y = 2;}printf("2\n");if(X == 1){printf("1 %d L\n",abs(bomb[i].x));}else if(X == 2){printf("1 %d R\n",abs(bomb[i].x));}if(Y == 1){printf("1 %d D\n",abs(bomb[i].y));}else if(Y == 2){printf("1 %d U\n",abs(bomb[i].y));}printf("3\n");}}

M - Bombs CodeForces - 350C(方格,模拟)相关推荐

  1. Bombs CodeForces - 350C

     题意:给定n个炸弹和炸弹的坐标,要求把所有炸弹拆除而且拆炸弹时不能踩到其它炸弹 题解:直接按路径长度排序然后拆就行了 #include<iostream> #include<cst ...

  2. 【codeforces 350C】Bombs

    [链接] 我是链接,点我呀:) [题意] [题解] 会发现在x轴以及y轴上的炸弹,能用较少的操作数除掉. 而其他的点,会发现操作数都是一样的. 那么先把x,y轴上的点都除掉. 其他点. 我们优先沿着横 ...

  3. CodeForces - 1491E Fib-tree(模拟)

    题目链接:点击查看 题目大意:给出一棵树,问是否为斐波那契树.斐波那契树的定义是,树的大小为斐波那契数列的其中一项,且可以通过删除掉一条边使其拆分的两个子树也为斐波那契树 题目分析:需要观察到,大小为 ...

  4. codeforces 719C (复杂模拟-四舍五入-贪心)

    题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑... 转载于:https://www.cnblogs.com/A--Q/p/5 ...

  5. Codeforces 67A【模拟】

    题意: 给一个字符串代表相邻学生的比较,L代表左边多,R表示右边多,=表示左右相等. 保证每个人拿糖>=1,在分糖最少的情况下,输出每个学生所分得的糖. 思路: 模拟一下,第一个人一开始拿1个, ...

  6. CodeForces - 786C——二分+模拟?

    [题目描述] Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. ...

  7. Vicious Keyboard CodeForces - 801A (暴力+模拟)

    题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个"VK"子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试 ...

  8. CodeForces - 1200C——小模拟

    [题目描述] Amugae is in a very large round corridor. The corridor consists of two areas. The inner area ...

  9. 【打CF,学算法——二星级】CodeForces 292A SMSC (模拟)

    [CF简介] 提交链接:CF 292A 题面: A. SMSC time limit per test   2 seconds memory limit per test  256 megabytes ...

最新文章

  1. 从FCKEDITOR到ckeditor(二) 撰写自定义对话框,增加数学公式(与webEq的结合)
  2. php exit、return、break、continue之间的差别,具体介绍
  3. 螺旋方阵(Leetcode第59题)
  4. 正则表达式小括号的多义性
  5. 刚进职场的IT前端小白,如何规划自己的未来之路?有哪些发展方向?
  6. 生意人没有“攀比”的目标,会过的很迷茫
  7. Tutorials 使用窗口功能分析信息
  8. 任正非谈鸿蒙系统研究,任正非谈鸿蒙系统 有优势 有信心打造生态
  9. 计算机数学的建议,2021考研计算机数学备考建议
  10. 单片机python教程推荐_有Python基础的小白如何学习单片机?
  11. 手把手教你使用R语言做出SCI论文中的表二(单因素分析表)(3)
  12. Unity学习 HTC Vive Hi5 2.0
  13. 如何卸载360安全客户端
  14. 百度人脸识别组件与mmkv冲突问题解决方案
  15. Blender 物理属性 (一)刚体
  16. linux常用命令及ip地址更改
  17. Swan Song 第十一周Scrum Meeting
  18. 《疑案里的中国史》——很多奇怪的历史故事其实都有合理的逻辑支撑
  19. ARM的SVC、IRQ和FIQ模式。
  20. 第五届信息科学、电气与自动化工程国际学术会议(ISEAE 2023)

热门文章

  1. 小程序源码放自己服务器上,小程序源码怎么安装到自己服务器?
  2. Error: docker-ce-cli conflicts with 2:docker-1.13.1-209.git7d71120.el7.centos.x86_64
  3. 6.6 PowerBI系列之DAX函数专题 -调节器TREATAS动态建立关系
  4. Apifox 生成接口文档 教程与操作步骤
  5. 用Java数组实现选队长的游戏
  6. 索引的底层实现原理是什么?
  7. 超详细图文保姆级教程:App开发新手入门(六)
  8. 【Qt入门第23篇】 数据库(三)利用QSqlQuery类执行SQL语句
  9. 数据库启动报ORA-03113错误
  10. MFC链表CList类