Codeforces Round #203 (Div. 2) C. Bombs

44 篇文章 0 订阅
C. Bombs
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

  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.

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.

Sample test(s)
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
要细心,排个序就好了!
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
#define M 100500
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct node {
    int x,y,c;
}p[M];
int stack[M],y[M];
char res[4]={'R','L','U','D'};
int isd(char c){
    if(c=='R')return 0;
    if(c=='L')return 1;
    if(c=='U')return 2;
    if(c=='D') return 3;
}
int fabs(int a){if(a<0)return -a;return a;}
bool cmp(node a,node b){
    if(a.c!=b.c)return fabs(a.c)<fabs(b.c);
    else if(a.x!=b.x)return a.x>b.x;
    else return fabs(a.y)<fabs(b.y);
}

int put1(int i){
    if(p[i].x>0)
    printf("1 %d %c\n",p[i].x,res[0]);
    else if(p[i].x<0)
    printf("1 %d %c\n",-p[i].x,res[1]);
    if(p[i].y>0)
    printf("1 %d %c\n",p[i].y,res[2]);
    else if(p[i].y<0)
    printf("1 %d %c\n",-p[i].y,res[3]);
}
int put2(int i){
    p[i].x=-p[i].x;p[i].y=-p[i].y;
    if(p[i].y>0)
    printf("1 %d %c\n",p[i].y,res[2]);
    else if(p[i].y<0)
    printf("1 %d %c\n",-p[i].y,res[3]);
    if(p[i].x>0)
    printf("1 %d %c\n",p[i].x,res[0]);
    else if(p[i].x<0)
    printf("1 %d %c\n",-p[i].x,res[1]);

}
int fun(int a,int b){
    if(a&&b)return 2;
    if(a&&!b)return 1;
    if(!a&&b)return 1;
    return 0;
}
int main()
{
    int n,i,ans;
    while(scanf("%d",&n)!=EOF){
        for(ans=n+n,i=0;i<n;i++){
            scanf("%d%d",&p[i].x,&p[i].y);
            ans+=2*fun(p[i].x,p[i].y);
            p[i].c=max(fabs(p[i].x),fabs(p[i].y));
        }
        sort(p,p+n,cmp);
        int re=0;
        printf("%d\n",ans);
        for(i=0;i<n;i++){
            put1(i);
            printf("2\n");
            put2(i);
            printf("3\n");
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值