Codeforces Round #199 (Div. 2) -- B. Xenia and Spies (简单模拟)
来源:互联网 发布:西门子触摸屏编程软件 编辑:程序博客网 时间:2024/05/29 12:28
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 ton from left to right.
Spy s has an important note. He has to pass the note to spyf. 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 isx, he can pass the note to another spy, eitherx - 1 or x + 1 (ifx = 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 stepti (steps are numbered from 1) Xenia watches spies numbersli, 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 spys to spy f as quickly as possible (in the minimum number of steps).
The first line contains four integers n,m, s andf (1 ≤ n, m ≤ 105; 1 ≤ s, f ≤ n; s ≠ f; n ≥ 2). Each of the followingm 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 stepi. If on step i the spy with the note must pass the note to the spy with a lesser number, thei-th character should equal "L". If on stepi the spy with the note must pass it to the spy with a larger number, thei-th character must equal "R". If the spy must keep the note at thei-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 charactersk 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 31 1 22 2 33 3 34 1 110 1 3
XXRR大体题意:有n 个间谍,标号为1到n,有m 行检查, 告诉你起点标号s,终点标号f。问如何去走才能从起点到终点!思路:简单模拟即可!当s!= f 就一直循环。先算出下一步是L 还是R,然后看看是不是在检查区间内,在的话 +X,否则 加ch = L || R!注意,连续的两个检查 时间可能跳度非常大,注意时间不想等就一直走就好了!#include<cstdio>#include<cstring>#include<algorithm>#include<vector>using namespace std;const int maxn = 1000000 + 10;vector<char>ans;char st[maxn];int l[maxn],r[maxn],t[maxn];int main(){ int n,m,s,f; while(scanf("%d %d %d %d",&n,&m,&s,&f) == 4 ){ for (int i = 0; i < m ;++i){ scanf("%d %d %d",&t[i],&l[i],&r[i]); } int cnt = 0; int i=0,j=1; while(s != f){// printf("%d\n",cnt); int ns = s; int ok = 1; char ch; if (s < f){ns = s+1;ch = 'R';} else { ns = s-1; ch = 'L'; } if (i < m && j == t[i]){ if (s >= l[i] && s <= r[i] || ns >= l[i] && ns <= r[i])ok=0; i++; } if (ok)st[cnt++]=ch,s=ns; else st[cnt++] = 'X'; ++j; } st[cnt] = 0; puts(st); } return 0;}
- Codeforces Round #199 (Div. 2) -- B. Xenia and Spies (简单模拟)
- Codeforces Round #199 (Div. 2) B. Xenia and Spies
- Codeforces Round #199(Div. 2) B. Xenia and Spies
- Codeforces Round #199 (Div. 2) B. Xenia and Spies(贪心)
- CF 342B(Xenia and Spies-模拟)
- CodeForces 342B Xenia and Spies(贪心)
- CodeForces 342B Xenia and Spies
- Codeforces Round #197 (Div. 2) B. Xenia and Ringroad
- Codeforces Round #197 (Div. 2)B. Xenia and Ringroad
- Codeforces Round #199 (Div. 2) A. Xenia and Divisors
- Codeforces Round #199 (Div. 2) E. Xenia and Tree
- Codeforces Round #199 (Div. 2) -- A. Xenia and Divisors (思路)
- Codeforces Round #199 (Div. 2) E. Xenia and Tree (非正规解法 分情况dfs)
- Codeforces Round #199 (Div. 2) E. Xenia and Tree(分块)
- Codeforces Round #107 (Div. 2) B (简单模拟)
- cf 342B - Xenia and Spies(贪心)
- Codeforces Round #197 (Div. 2) C. Xenia and Weights - 搜索
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
- python判断一个字符是不是在一个字符串中关键字in ,not in
- QT 子窗口获取父窗口指针的方法
- 切换控制器的时候隐藏搜索栏按钮,隐藏键盘,取消第一响应
- Cfile的小BUG
- 相机对焦原理
- Codeforces Round #199 (Div. 2) -- B. Xenia and Spies (简单模拟)
- JavaScript构造函数和普通函数
- 玩转树莓派之四----rasp-config配置
- 网络字节序----阿里巴巴2015实习生笔试题
- c++ 流的注意事项
- Android 豆瓣电影-网络缓存实现与分析
- github push rejected问题
- Ajax处理XML、HTML、JSON三种数据格式的方法
- java构造器的作用