CF350C.Bombs

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

你有一个机器人,其任务是在一个正方形平面上拆除炸弹。具体而言,该正方形平面上共有 nn 颗炸弹,其中第 ii 颗炸弹位于坐标为 (xi,yi)(x_i, y_i) 的点上。已知任意两颗炸弹均不位于同一点,且没有任何一颗炸弹位于坐标原点 (0,0)(0, 0)。初始时,机器人位于坐标 (0,0)(0, 0)。我们记机器人当前所在位置为 (x,y)(x, y)。为拆除所有炸弹,机器人可执行以下三类操作:

  1. 操作格式为 "1 k dir"。执行该操作时,机器人需沿方向 dir 移动 kk 次(其中 k≥1k \geq 1)。机器人仅可朝四个方向移动:“R”(右)、“L”(左)、“U”(上)、“D”(下)。每次移动时,机器人可从当前点 (x,y)(x, y) 移动至下列四点之一:(x+1,y)(x + 1, y)、(x−1,y)(x - 1, y)、(x,y+1)(x, y + 1)、(x,y−1)(x, y - 1)(分别对应上述四个方向)。若从点 (x,y)(x, y) 出发的移动路径上(除终点外)存在至少一颗炸弹,则该次移动被禁止。

  2. 操作格式为 "2"。执行该操作时,机器人需在当前位置 (x,y)(x, y) 拾取一颗炸弹,并将其放入一个特殊容器中。由此,机器人可将炸弹从任意点携带至任意其他点。若当前位置 (x,y)(x, y) 上没有炸弹,则该操作不可执行;若机器人容器中已有一颗炸弹,则禁止再次拾取炸弹。

  3. 操作格式为 "3"。执行该操作时,机器人需从容器中取出一颗炸弹并将其销毁。仅当机器人位于坐标原点 (0,0)(0, 0) 时,才允许执行该操作;若容器中无炸弹,则禁止执行该操作。

请帮助机器人找出一个最短的操作序列,使其能够拆除坐标平面上的所有炸弹。

输入格式

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 (x__i, y__i) ( - 109 ≤ x__i, y__i ≤ 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).

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 坐标平面上炸弹的数量。接下来的 nn 行每行包含两个整数。第 ii 行包含两个数 (xi,yi)(x_i, y_i)(−109≤xi,yi≤109-10^9 \leq x_i, y_i \leq 10^9)—— 第 ii 个炸弹的坐标。保证任意两个炸弹不位于同一点,且没有炸弹位于原点 (0,0)(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 ≤ 106.

在一行中输出一个整数 kk —— 摧毁所有炸弹所需的最少操作次数。
在接下来的若干行中,输出这 kk 次操作的描述。若存在多种可行序列,输出任意一种即可。
题目保证存在满足 k≤106k \leq 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

输入解题思路,AI测评打分。不知道怎么写?

首页