codeforces342B
Xenia and Spies
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.
Examples
3 5 1 3
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3
XXRR sol:题意很鬼畜,看了半天都没懂
题意:给定 n 个间谍,m个区间,一个 s,一个f,然后从 s开始传纸条,然后传到 f,
然后在每个 t 时间在区间内的不能传,问你最少的时间传过去。
然后直接暴力模拟即可
/*
题意:给定 n 个间谍,m个区间,一个 s,一个f,然后从 s开始传纸条,然后传到 f,
然后在每个 t 时间在区间内的不能传,问你最少的时间传过去。
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,Sta,End;
struct Not
{
int Time,l,r;
inline bool operator<(const Not &tmp)const
{
return Time<tmp.Time;
}
}a[N];
int main()
{
int i,opt,Time=,Now=;
R(n); R(m); R(Sta); R(End);
opt=(Sta<End)?:-;
for(i=;i<=m;i++)
{
R(a[i].Time); R(a[i].l); R(a[i].r);
}
sort(a+,a+m+);
while(Sta!=End)
{
if(a[Now].Time==Time)
{
int Weiz=Sta+opt;
bool Flag=;
while(a[Now].Time==Time&&Now<=m)
{
if((Weiz>=a[Now].l&&Weiz<=a[Now].r)||(Sta>=a[Now].l&&Sta<=a[Now].r)) Flag=;
Now++;
}
if(Flag) putchar('X');
else
{
(opt==)?putchar('R'):putchar('L'); Sta+=opt;
}
}
else
{
(opt==)?putchar('R'):putchar('L'); Sta+=opt;
}
Time++;
}
return ;
}
/*
Input
3 5 1 3
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3
Output
XXRR Input
5 11 1 5
1 1 5
2 2 2
3 1 1
4 3 3
5 3 3
6 1 1
7 4 4
8 4 5
10 1 3
11 5 5
13 1 5
Output
XXXRXRXXRR
*/
codeforces342B的更多相关文章
随机推荐
- MySQL InnoDB 修改表列Online DDL
概述 一般来说数据库结构一经设计,不能轻易更改,因为更改DDL(Data Definition Language)操作代价很高,所以在进行数据库结构设计时需要谨慎. 但是业务发展是未知的,特别是那些变 ...
- TensorFlow tutorial
代码示例来自https://github.com/aymericdamien/TensorFlow-Examples tensorflow先定义运算图,在run的时候才会进行真正的运算. run之前需 ...
- 配置CLion作为Qt5开发环境
使用Qt进行程序开发时QtCreator总是不二之选.作为老牌IDE在提供了强大的功能同时也对Qt的支持做了许多优化.如果没有特别的原因你应该使用它. 然而一个顺手的工具将会极大得提升生产效率,而如果 ...
- 69道Spring面试题和答案,简单明了无套路
目录 Spring 概述 依赖注入 Spring beans Spring注解 Spring数据访问 Spring面向切面编程(AOP) Spring MVC Spring 概述 1. 什么是spri ...
- 利用AccessibilityService自动获取微信号(Android)
前言: 最近遇到一个需求,要求写一个小插件,能够自动在微信的页面弹出一个窗口,展示用户的相关信息(与我们公司有关的信息,方便运营快速了解用户信息). 当时我第一反应是不可能,如果能够在别的app中获取 ...
- Linux使用wget、安装Python
原文:https://blog.csdn.net/ghost_chou/article/details/81905302 1.指定需要安装的目录或创建并访问到该选择的目录下. mkdir /data/ ...
- SQLServer之锁简介
锁定义(Definition) 锁定是 DBMS 将访问限制为多用户环境中的行的过程. 以独占方式锁定行或列,不允许其他用户访问锁定的数据,直到锁被释放. 这可确保两个用户不能同时更新行中的同一列. ...
- windows10下安装kali子系统
写在前面 为什么我会想到在窗下装一个卡利 作为一个小白,平时做CTF题的时候,有时会用到python2.7环境(比如一些脚本需要,还有窗户下用的SqlMap的话,好像只支持在python2.7,之前被 ...
- 记录Html+Css流程表格
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 《Python 数据科学实践指南》读书笔记
文章提纲 全书总评 C01.Python 介绍 Python 版本 Python 解释器 Python 之禅 C02.Python 基础知识 基础知识 流程控制: 函数及异常 函数: 异常 字符串 获 ...