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).
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.
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.
3 5 1 3 1 1 2 2 2 3 3 3 3 4 1 1 10 1 3
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;
}