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 ≤ lirin). 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, fnsfn ≥ 2). Each of the following m lines contains three integers ti, li, ri (1 ≤ ti ≤ 109, 1 ≤ lirin). 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
就是简单的模拟,如果,可以目标走,就走,不能走就输出X就可以了!
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define M 100050
struct node {
int t,l,r;
}p[M];
int m;
bool find(int x,int a,int b){
int s=0,e=m-1,mid;
while(s<=e){
mid=(s+e)>>1;
if(p[mid].t==x){
if((a<p[mid].l||a>p[mid].r)&&(b<p[mid].l||b>p[mid].r))return true;
else return false;
}
else if(p[mid].t<x)
s=mid+1;
else if(p[mid].t>x)
e=mid-1;
}
return true;
}
int main()
{
int n,s,f,i,ans;char c;
while(scanf("%d%d%d%d",&n,&m,&s,&f)!=EOF){
if(s<f)c='R',ans=1;
else c='L',ans=-1;
for(i=0;i<m;i++){
scanf("%d%d%d",&p[i].t,&p[i].l,&p[i].r);
}
int t=1;
while(s!=f){
if(find(t,s,s+ans)) s+=ans,printf("%c",c);
else printf("X");
t++;
}
printf("\n");
}
return 0;
}

Codeforces Round #199 (Div. 2) B. Xenia and Spies的更多相关文章

  1. Codeforces Round #199 (Div. 2) E. Xenia and Tree

    题目链接 2了,差点就A了...这题真心不难,开始想的就是暴力spfa就可以,直接来了一次询问,就来一次的那种,TLE了,想了想,存到栈里会更快,交又TLE了..无奈C又被cha了,我忙着看C去了.. ...

  2. Codeforces Round #199 (Div. 2) A Xenia and Divisors

    注意题目的数字最大是7 而能整除的只有 1,2,3,4,6,故构成的组合只能是1,2,4 或1,2,6或1,3,6,故分别统计1,2,3,4,6的个数,然后再分配 #include <iostr ...

  3. Codeforces Round #199 (Div. 2) D. Xenia and Dominoes

    把 'O' 看成 'X',然后枚举它的四个方向看看是否能放,然后枚举 $2^4$ 种可能表示每种方向是否放了,放了的话就标成 'X',就相当于容斥,对于新的图去dp. dp就是铺地砖,行用二进制来表示 ...

  4. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  5. Codeforces Round #199 (Div. 2)

    A.Xenia and Divisors 题意:给定N个数,每个数的取值范围为1-7,N是3的倍数,判定是否能够恰好将N个数分成若干三元组,使得一个组中的元素a,b,c满足 a < b < ...

  6. Codeforces Round #199 (Div. 2) C. Cupboard and Balloons

    C. Cupboard and Balloons time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)

    题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...

  9. Codeforces Round #515 (Div. 3)

    Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...

随机推荐

  1. Qt 技巧:去除对话框边框 + 设置窗口可移动和透明

    1.去除对话框标题栏和边框 在构造函数里设置:    this->setWindowFlags(Qt::FramelessWindowHint); Qt::Dialog     (按照对话框的形 ...

  2. cocos2dx进阶学习之CCSpriteBatchNode

    继承关系 CCSpriteBatchNode -> CCNode, CCTextureProtocol 成员变量 inline CCTextureAtlas* getTextureAtlas(v ...

  3. BZOJ 3039: 玉蟾宫

    3039: 玉蟾宫 Description 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. 这片土地被分成N*M个格子,每个 ...

  4. 动态弹球的实现 加入了多线程技术--javaSE游戏准备工作

    任务描述:实现了动态弹球的功能,对于有弹球功能的SE游戏奠定了基础. package 运用线程技术的小球; import java.awt.*; import java.awt.event.*; im ...

  5. CSDN排名第一和第二的人

    http://blog.csdn.net/phphot http://blog.csdn.net/yuanmeng001

  6. MCU开发之I2C通信

    程序状态字PSW是8位寄存器,用于存放程序运行的状态信息,PSW中各位状态通常是在指令执行的过程中自动形成的,但也可以由用户根据需要采用传送指令加以改变.各个标志位的意义如下: PSW.7(Cy):进 ...

  7. Ant学习实例

    ant   目录(?)[+] Ant学习实例 安装Ant 基础元素 project元素 target元素 property元素 完整示例   Ant学习实例 1.安装Ant 先从http://ant. ...

  8. 深入浅出Win32多线程设计之MFC的多线程-线程与消息队列(经典)

    1.创建和终止线程 在MFC程序中创建一个线程,宜调用AfxBeginThread函数.该函数因参数不同而具有两种重载版本,分别对应工作者线程和用户接口(UI)线程. 工作者线程 CWinThread ...

  9. Hdu 1175 连连看(DFS)

    Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1175 因为题目只问能不能搜到,没问最少要几个弯才能搜到,所以我采取了DFS. 因为与Hdu ...

  10. 一步一步重写 CodeIgniter 框架 (7) —— Controller执行时将 Model获得的数据传入View中,实现MVC

    1. 实现过程 1) 上一节讲述了 View 视图的加载过程,它是在 Loader 类中加载的,并通过 Include 语句进行包含.那么为了在 View 中传递变量,只需要在 include 语句所 ...