Codeforces Round #199 (Div. 2) B. Xenia and Spies
2 seconds
256 megabytes
standard input
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 ≤ 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
就是简单的模拟,如果,可以目标走,就走,不能走就输出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的更多相关文章
- Codeforces Round #199 (Div. 2) E. Xenia and Tree
题目链接 2了,差点就A了...这题真心不难,开始想的就是暴力spfa就可以,直接来了一次询问,就来一次的那种,TLE了,想了想,存到栈里会更快,交又TLE了..无奈C又被cha了,我忙着看C去了.. ...
- 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 ...
- Codeforces Round #199 (Div. 2) D. Xenia and Dominoes
把 'O' 看成 'X',然后枚举它的四个方向看看是否能放,然后枚举 $2^4$ 种可能表示每种方向是否放了,放了的话就标成 'X',就相当于容斥,对于新的图去dp. dp就是铺地砖,行用二进制来表示 ...
- 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...
- Codeforces Round #199 (Div. 2)
A.Xenia and Divisors 题意:给定N个数,每个数的取值范围为1-7,N是3的倍数,判定是否能够恰好将N个数分成若干三元组,使得一个组中的元素a,b,c满足 a < b < ...
- 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 ...
- 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 ...
- Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)
题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...
- Codeforces Round #515 (Div. 3)
Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...
随机推荐
- WebRTC–getUserMedia-filter
示例说明:抓取MediaStream的一帧数据,并对该帧数据使用Css滤镜效果. 步骤: 1. 由getUserMedia方法获取一个可用的MediaStream 2. canvas方法drawIma ...
- 最详细最实用-Orcad10.5安装说明
接受协议 选择安装 忽略警告 全部为空 忽略警告 直接下一步 选择YES 为空,直接下一步 全选,根据需要修改该路径,下一步 根据需要修改该路径 下一步 直接next 忽略提示 直接下一步 直接下一步 ...
- XMPP--- error : linker command failed with exit code 1
error: linker command failed with exit code 1 (use -v to see invocation) 错误原因:libidn.a文件没添加上去 解决方法:l ...
- 【Eclipse】修改java代码不强制重启
找到tomcat的server.xml文件,修改以下代码,重新发布重启.然后修改java代码就可以不用重启了. 将reloadable=“true”改成reloadable="false&q ...
- ubuntu使用postgist,pgrouting
安装过程 一 :所需组件1 PostgreSQL 9.4 or higher.2 Proj4 .reprojection library.3 GEOS .geometry library.4 LibX ...
- Python之路Day6
Day6的主要内容是: configparser模块 shutil模块 subprocess模块 处理xml的模块 1.configparser模块 #! /usr/bin/env python # ...
- android Listview,gridview局部刷新,部分刷新
众所周知Listview和Gridview的刷新界面的方式是调用adapter.notifyDataSetChanged()进行界面刷新. 但是此方法有其弊端,他是将界面中的数据全部刷新一遍,不论数据 ...
- Android基础【1】杀死进程(强行停止)应用程序的方法
写在前面: 进入手机ODM已经很久,经历过几个项目项目下来,对高通.展讯.Marvell平台都进行了接触,对于我个人来说,参与手机系统项目的开发与维护,最明显的好处是可以深入的了解某一功能的具体实现过 ...
- android的fragment基本介绍
可以分为下面的几部分: 使用支持库 创建一个Fragment 创建一个动态UI 多个Fragment之间的通信 1.使用支持库 如果您的应用需要运行在3.0及以上的版本,可以忽略这部分内容. 如果您的 ...
- source insight 中文注释为乱码解决
1. source insight 中文注释为乱码解决 http://blog.csdn.net/bingfeng1210/article/details/7527059 2. Source Insi ...