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的更多相关文章
随机推荐
- 深度学习之卷积神经网络(CNN)详解与代码实现(一)
卷积神经网络(CNN)详解与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/10430073.html 目 ...
- Linux通配符应用详解
一.强大的“*” “*”在通配符中是最常用的一种,代表0个.一个或多个字符.在使用中有三种情况,表示三种不同的含义. 1.单独的“*” 这里指的是只有“*”出现的情况,默认为单独的一个,当然连续敲两个 ...
- C#复制文件全代码--供参考
private void button1_Click(object sender, EventArgs e) { //创建文件对象 FileInfo fi = null; //实例化打开文件对话框 O ...
- SpringBoot2.0整合Redis
Spring Boot2.0在2018年3月份正式发布,相比1.0还是有比较多的改动,例如SpringBoot 自2.0起支持jdk1.8及以上的版本.第三方类库升级.响应式 Spring 编程支持等 ...
- oracle学习笔记(六) JDBC使用
JDBC使用 1. 导包 直接使用IDEA导入依赖包即可 新建一个lib,把jar包放在这里 2. 加载驱动 Class.forName("oracle.jdbc.driver.Oracle ...
- headfirst设计模式(5)—工厂模式体系分析及抽象工厂模式
先编一个这么久不写的理由 上周我终于鼓起勇气翻开了headfirst设计模式这本书,看看自己下一个设计模式要写个啥,然后,我终于知道我为啥这么久都没写设计模式了,headfirst的这个抽象工厂模式, ...
- vue学习记录③(路由)
上篇文章我们用vue-cli脚手架工具做了个简单的hello world页面,但是我们破坏了原来的流程,而正常的访问页面应该是通过路由来实现的. 那么什么是路由呢? 路由就是通过不同的url来访问不同 ...
- 《全栈营销之如何制作个人博客》之一:用什么开发语言和CMS系统
现在的互联网,已经不再是初级互联时代,是需要全方位营销,自建粉丝池的时代,云码素材从提出全栈营销,到实践分析,总结出全栈营销第一步,先制作一个个人博客是最好的开始.今天开始就跟我一起学习如何制作一个精 ...
- 前端入门23-CSS预处理器(Less&Sass)
声明 本篇内容梳理自以下几个来源: Github:smyhvae/web Bootstrap网站的 less 文档 Sass中文网 感谢大佬们的分享. 正文-CSS预处理(less&Sass) ...
- 华为7.0系统最简单激活xposed框架的流程
对于喜欢搞机的哥们而言,很多时候会接触到Xposed框架及其种类繁多功能无敌的模块,对于5.0以下的系统版本,只要手机能获得root权限,安装和激活Xposed框架是异常简易的,但随着系统版本的不断更 ...