大水题,如果给的step走完了,但是没走到终点的话,还要继续走。比赛wa掉了
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 100005;
struct node {
int id;
int l,r;
} a[maxn];
int main()
{
int n,m,s,f;
while(scanf("%d %d %d %d",&n,&m,&s,&f) != -1) {
for(int i = 0; i < m; ++i)
scanf("%d %d %d",&a[i].id,&a[i].l,&a[i].r);
int step;
if(s < f) step = 1;
else step = -1;
int cnt = 0, stepcnt = 1;
int ti = s;
bool flag = 0;
while(!flag) {
if(cnt >= m){
if(step < 0) printf("L");
else printf("R");
ti += step;
if(ti == f) flag = 1;
continue;
}
if(stepcnt < a[cnt].id) {
if(step < 0) printf("L");
else printf("R");
++stepcnt;
ti += step;
if(ti == f) flag = 1;
} else {
int tmp = ti+step;
if((ti >= a[cnt].l) && (ti <= a[cnt].r)) {
printf("X");
++stepcnt;
++cnt;
} else if((tmp >= a[cnt].l) && (tmp <= a[cnt].r)) {
printf("X");
++stepcnt;
++cnt;
} else {
if(step < 0) printf("L");
else printf("R");
++stepcnt;
++cnt;
ti += step;
if(ti == f) flag = 1;
}
}
}
printf("\n");
}
return 0;
}