Codeforces Round #199(Div. 2) B. Xenia and Spies

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.

Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is x, he can pass the note to another spy, either x - 1 or x + 1 (if x = 1 or x = n, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.

But nothing is that easy. During m steps Xenia watches some spies attentively. Specifically, during step ti (steps are numbered from 1) Xenia watches spies numbers li, li + 1, li + 2, ..., ri (1 ≤ li ≤ ri ≤ n). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.

You've got s and f. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy s to spy f as quickly as possible (in the minimum number of steps).

Input

The first line contains four integers nms and f (1 ≤ n, m ≤ 105; 1 ≤ s, f ≤ ns ≠ fn ≥ 2). Each of the following m lines contains three integers ti, li, ri (1 ≤ ti ≤ 109, 1 ≤ li ≤ ri ≤ n). It is guaranteed that t1 < t2 < t3 < ... < tm.

Output

Print k characters in a line: the i-th character in the line must represent the spies' actions on step i. If on step i the spy with the note must pass the note to the spy with a lesser number, the i-th character should equal "L". If on step i the spy with the note must pass it to the spy with a larger number, the i-th character must equal "R". If the spy must keep the note at the i-th step, the i-th character must equal "X".

As a result of applying the printed sequence of actions spy s must pass the note to spy f. The number of printed characters k must be as small as possible. Xenia must not catch the spies passing the note.

If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.

Sample test(s)
input
3 5 1 3
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3
output
XXRR

题目大意:有n个间谍,编号(1~n),第s个要把note传递到f;整个过程是分step的,每一个step间谍都可以有所行动,但是某些step被xx侦探监视了,监视的是一个区间,该区间的间谍既不能把note传递出去,也不能接受传递,间谍的行动分为三种L(向左传递)、R(向右传递)、X(不作为)。输出完成任务的行动序列。(保证可以完成)。

题目分析:模拟。(提到模拟,无论从简单到难,都有一个永远不变的问题,那就是一定要分析清楚过程,这种类型的题目是最能反映一句名言的:细节决定成败。)

我们来看看注意的细节:

1、既然是模拟,模拟是以时间(step)为线索的,那么我们开一个step数组记录每一步的监视情况可以吗?显然不行:(1 ≤ ti ≤ 109)。由题目中t的输入一定是从小到大的,我们只要开一个m大小的结构体就够了,当然t是一定要被记录的。

2、既然采用上面对step的记录方式,那么就会在处理中引起一些小问题:当前步骤不是结构体数组的步骤,那么我们不能把这组数据丢掉,我们直接向这目标前进,i--就行了。

3、当0~m的数组跑完了,监视没有了,但是我们的note还没有传递到目标间谍的手上,这时候我们要继续传递。

AC代码:

#include<cstdio>
#include<cstring>
struct node
{
    int id,l,r;
}a[100005];
int main()
{
    int n,m,s,f;
    while(scanf("%d %d %d %d",&n,&m,&s,&f)!=EOF)
    {
        memset(a,0,sizeof a);
        for(int i=0;i<m;i++)
            scanf("%d %d %d",&a[i].id,&a[i].l,&a[i].r);
        int t=1,note=s;
        for(int i=0;i<m;i++)
        {
            if(note==f)
                break;
            if(a[i].id!=t)
            {
                if(s<f)
                {
                    printf("R");
                    note++;
                }
                else if(s>=f)
                {
                    printf("L");
                    note--;
                }
                i--;
            }
            else if(s<f && (a[i].l>note+1 || a[i].r<note))
            {
                printf("R");
                note++;
            }
            else if(s>=f && (a[i].l>note || a[i].r<note-1))
            {
                printf("L");
                note--;
            }
            else
                printf("X");
            t++;
        }
        while(note!=f) ///监视完了,任务还没有完。
        {
            if(s<f)
            {
                printf("R");
                note++;
            }
            else if(s>=f)
            {
                printf("L");
                note--;
            }
        }
        puts("");
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值