SDKD 2016 Summer Single Contest #03.B

Description
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 n, m, s and f(1 ≤ n, m ≤ 105; 1 ≤ s, f ≤ n; s ≠ f; n ≥ 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 Input
Input
3 5 1 3
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3
Output
XXRR
题目:
这个题错的只能怪我自己了, 我是下一个else 的while()直接复制粘贴的,
所以s++还是原来的样子, 所以Memory limit exceeded Time limit exceeded on test 2
一直出现,当时疯了都,就是找不出来~~
如果 f 在s的右边 只输出 X或者R就好了,往左走的话就得不偿失了
注:也可以不用ans存直接输出.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 1;
int n, m, s, f;

string ans;
int tt[maxn];
int l[maxn];
int r[maxn];
int main()
{
    cin >> n >> m >> s >> f;
    for(int i = 0; i < m; i++)
    {
        scanf("%d", &tt[i]);
        scanf("%d%d", &l[i], &r[i]);
    }
    int i = 0;
    long long t = 0;

    if(f > s)
        while(1)
        {
            t++;
            if(tt[i] == t)
            {
            //当s在侦查范围内是不能动的,并且在左边界减一的位置
            //不动.
                if(s >= l[i] && s <= r[i] || s+1 == l[i])
                    ans += 'X';
                else
                    {ans += 'R';s++;}
                i++;
            }
            else
                {ans += 'R';s++;}
            if(s == f)
                break;
        }
    else
        while(1)
        {
            t++;
            if(tt[i] == t)
            {
            //类似上面
                if(s >= l[i] && s <= r[i] || s-1 == r[i])
                    ans += 'X';
                else
                    {ans += 'L';s--;}
                i++;
            }
            else
                {ans += 'L';s--;}
            if(s == f)
                break;
        }
    cout << ans <<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值