CodeForces 342B Xenia and Spies

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

看到这道题不经要吐槽一下

Day 4, Day 5这两天萌萌哒队长都放了很多重题

特别是Div2 ╮(╯▽╰)╭

结果碧荷大大6分钟就交了7道题

把新来的童鞋都吓坏了(⊙o⊙)…


言归正传,这道题大意是有一个间谍在被审讯的过程中要把一本重要的书传给另一个人

所有人按照一字排开,只能一个人一个人地传过去

但是警察蜀黍也不傻啊,总会盯着几个人看的

被盯着的时候总不能传吧o(╯□╰)o

假设把书传给身边的人需要一个单位时间

如果运气不好被警察蜀黍盯上了只能把书留着暂时不传,一次也记作一个单位时间

给出相应时间点警察蜀黍会盯着看的人的范围,问第i个间谍要传给第j个间谍至少需要多少个单位时间


想法很简单,贪心

一直朝着目标方向传,如果此时被盯着就不传,如果没被盯就传过去

直到传到目标间谍手里


但是有间谍j有可能在间谍i的左边或右边

所以要分两个方向处理


代码如下:

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;

char seq[1000000+5];

int main() {
  int n, m, s, f;
  cin >> n >> m >> s >> f;
  int state[m][3];
  for (int i = 0; i < m; i++) cin >> state[i][0] >> state[i][1] >> state[i][2];
  
  int cnt = 0;
  if (s < f) {
    memset(seq, 'R', sizeof(seq));
    for (int i = 0; i < m; i++) {
      int prev_pos = s+state[i][0]-cnt;
      //cout << prev_pos-1 << endl;
      if (prev_pos-1 >= f) break;
      if ((prev_pos >= state[i][1] && prev_pos <= state[i][2]) ||
          (prev_pos-1 >= state[i][1] && prev_pos-1 <= state[i][2])) { cnt++; seq[state[i][0]] = 'X'; }
      //cout << state[i][0] << endl;
    }
  }
  else {
    memset(seq, 'L', sizeof(seq));
    for (int i = 0; i < m; i++) {
      int prev_pos = s-(state[i][0]-cnt);
      if (prev_pos+1 <= f) break;
      if ((prev_pos >= state[i][1] && prev_pos <= state[i][2]) ||
          (prev_pos+1 >= state[i][1] && prev_pos+1 <= state[i][2])) { cnt++; seq[state[i][0]] = 'X'; }
    }
  }
  //cout << cnt+f-s << endl;
  for (int i = 1; i <= cnt+abs(f-s); i++) cout << seq[i];
  //cout << seq[3] << endl;
  cout << endl;
  return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值