Codeforces Round #199 (Div. 2) B. Xenia and Spies(贪心)

44 篇文章 0 订阅
15 篇文章 0 订阅

题目地址: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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值