Test instructions: Given n spies, M-bands, an S, an F, and then from S to pass the note, and then to F, and then in each t time within the interval of the can not pass, ask you the least time passed.
Analysis: This problem, on the simulation of a good, greedy strategy, can pass on, find a good direction, always pass on the line, to the end of F.
The code is as follows:
#include <bits/stdc++.h>using namespace std;struct node{int L, R, T; BOOL operator < (const node &p) const{return T < p.t; }};node A[100005];int Main () {int S, T, M, N, F, L, R; while (CIN >> n >> m >> s >> f) {bool OK = false; int x = f > S? 1:-1; int pos = s; for (int i = 0; i < m; ++i) {scanf ("%d%d%d", &a[i].t, &A[I].L, &A[I].R); }//sort (A, a+m); int cnt = 0; for (int i = 1;; ++i) {if (a[cnt].t = = i) {if (pos + x < A[CNT].L && Pos < A[CNT].L ) || (pos + x > A[CNT].R && pos > A[CNT].R)) {printf ("%c", x < 0?) ' L ': ' R '); pos + = x; } else printf ("X"); if (pos = = f) break; ++cnt; }else{pos + = x; printf ("%c", x < 0?) ' L ': ' R '); if (pos = = f) break; } }printf ("\ n"); } return 0;}
Codeforces 342B Xenia and Spies (water problem simulation, greed)