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 ...
随机推荐
- QT设置前景图位置(配色简单漂亮)
QPushButton { background-image: url(:/Resources/green_click.png); image: url(:/Resources/toolsbutton ...
- 如何提高banner设计含量--网上的一篇文章--感悟
"修改": 本质上是改什么?改大小?图片?文字?颜色? 老板说:修改本质上是提高“设计含量”.检测一个作品设计含量的高低,可以将作品中每一个设计元素进行分析,看它的“属性”与“操作 ...
- SWIFT学习笔记01
1.Swift.用来推断option是不是nil,相当于OC的 if(option) if let name = option{ greeting = "if=====" }els ...
- Android图片异步加载的方法
很多时候,我们在加载大图片或者需要处理较多图像数据的时候,希望显示效果能好点,不至于因为图片解码耗时产生ANR等情况,不得不说异步加载是个不错的方法.说到异步加载,避免application出现ANR ...
- [HDU 1016]--Prime Ring Problem(回溯)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- [Swust OJ 1026]--Egg pain's hzf
题目链接:http://acm.swust.edu.cn/problem/1026/ Time limit(ms): 3000 Memory limit(kb): 65535 hzf ...
- GIT分支操作常用命令
切换分支:git checkout name 撤销修改:git checkout -- file 删除文件:git rm file 查看状态:git status 添加记录:git add file ...
- 转:CSS选择器笔记
作者: 阮一峰 日期: 2009年3月12日 去年我学jQuery的时候,曾经做过一点选择器(selector)的笔记. 这几天拿出来看了一下,发现很多都忘记了.所以,我决定把它们贴在这里,方便以后查 ...
- Menu的自己定义实现-------保卫萝卜造塔升级塔菜单实现
cocos2dx原生的menu排版函数实现的非常无完整,像最主要的Item的排序要想做得略微美丽一些就须要我们自己实现. 对于Menu我们能够用两种方法来实现: 1.大神级别. 继承自Control, ...
- First_1
#region 练习题 1.4 (1) ///*求一个N阶方阵所有原素的和.(改进:二维数组的大小可以自己输入)*/ //Console.WriteLine("请输入i和j的值:" ...