题目地址:http://codeforces.com/problemset/problem/342/B
思路:在某时刻,若能传这一直向目标方向传递,若不能则等待。
#include<map>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5+50;
struct Node
{
int t,l,r;
};
int n,m,s,f;
vector<int> ans;
Node M[maxn];
int cmp(Node a,Node b)
{
return a.t<b.t;
}
int main()
{
scanf("%d%d%d%d",&n,&m,&s,&f);
for(int i=0; i<m; i++)
scanf("%d%d%d",&M[i].t,&M[i].l,&M[i].r);
sort(M,M+m,cmp);
int time=0,num=0;
if(s<=f)
{
while(s!=f)
{
time++;
if(time==M[num].t)
{
if((s>=M[num].l&&s<=M[num].r)||((s+1)>=M[num].l&&(s+1)<=M[num].r))
ans.push_back('X');
else
{
ans.push_back('R');
s++;
}
num++;
}
else
{
ans.push_back('R');
s++;
}
}
}
else
{
while(s!=f)
{
time++;
if(time==M[num].t)
{
if((s>=M[num].l&&s<=M[num].r)||((s-1)>=M[num].l&&(s-1)<=M[num].r))
ans.push_back('X');
else
{
ans.push_back('L');
s--;
}
num++;
}
else
{
ans.push_back('L');
s--;
}
}
}
for(int i=0; i<ans.size()-1; i++)
printf("%c",ans[i]);
printf("%c",ans[ans.size()-1]);
return 0;
}