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的更多相关文章
随机推荐
- C++求集合的交集差集
标准库的<algorithm>头文件中提供了std::set_difference,std::set_intersection和std::set_union用来求两个集合的差集,交集和并集 ...
- 使用C#开发windows服务定时发消息到钉钉群_群组简单消息
前言:本提醒服务,是由C#语言开发的,主要由windows服务项目和winform项目组成,运行服务可实现功能:向钉钉自定义机器人群组里,定时,定次,推送多个自定义消息内容,并实现主要功能的日志记录. ...
- HashMap源码分析 JDK1.8
本文按以下顺序叙述: HashMap的感性认识. 官方文档中对HashMap介绍的解读. 到源码中看看HashMap这些特性到底是如何实现的. 把源码啃下来有一种很爽的感觉, 相信你读完后也能体会到~ ...
- SAP MM A工厂下的PR可以转成B工厂下的PO?
SAP MM A工厂下的PR可以转成B工厂下的PO? 答案是可能的,这也是SAP标准行为之一. 如下图采购申请单据, PR中的Plant是GENL.该PR 已经转成了PO,如上图. 看这个PO,工厂代 ...
- MySQL安装之yum安装
转载来源:https://www.cnblogs.com/brianzhu/p/8575243.html 1. 下载并安装MySQL官方的 Yum Repository 1 [root@BrianZh ...
- Python使用Plotly绘图工具,绘制直方图
今天我们再来讲解一下Python使用Plotly绘图工具如何绘制直方图 使用plotly绘制直方图需要用到graph_objs包中的Histogram函数 我们将数据赋值给函数中的x变量,x = da ...
- Java学习资源整理(超级全面)
这里整理一些自己平常搜集的比较好的关于Java的学习资源,主要包括博客站点.书籍.课程等. 了解Java最新资讯 这部分主要是了解与Java相关的动态以及信息,能够拓展我们的视野以及寻找一些好的ide ...
- python中json文件处理涉及的四个函数json.dumps()和json.loads()、json.dump()和json.load()的区分
一.概念理解 1.json.dumps()和json.loads()是json格式处理函数(可以这么理解,json是字符串) (1)json.dumps()函数是将一个Python数据类型列表进行js ...
- Java Memory Management
How Memory works in Java The role of the stack - Each time you call a function, Java pushed the loca ...
- python3 json数据格式的转换(dumps/loads的使用、dict to str/str to dict、json字符串/字典的相互转换)
在写网络爬虫的时候,有时候会抓取到一些json格式的字符串,想要通过python字典的方式对字串中的内容进行寻址,则需要将json字符串先转换为python字典. dumps()函数: loads() ...