zoukankan      html  css  js  c++  java
  • Codeforces Round #199 (Div. 2) B. Xenia and Spies

    B. Xenia and Spies
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.

    Spy s has an important note. He has to pass the note to spy f. 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 is x, he can pass the note to another spy, either x - 1 or x + 1 (if x = 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 step ti (steps are numbered from 1) Xenia watches spies numbers li, li + 1, li + 2, ..., ri (1 ≤ lirin). 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 spy s to spy f as quickly as possible (in the minimum number of steps).

    Input

    The first line contains four integers nms and f (1 ≤ n, m ≤ 105; 1 ≤ s, fnsfn ≥ 2). Each of the following m lines contains three integers ti, li, ri (1 ≤ ti ≤ 109, 1 ≤ lirin). It is guaranteed that t1 < t2 < t3 < ... < tm.

    Output

    Print k characters in a line: the i-th character in the line must represent the spies' actions on step i. If on step i the spy with the note must pass the note to the spy with a lesser number, the i-th character should equal "L". If on step i the spy with the note must pass it to the spy with a larger number, the i-th character must equal "R". If the spy must keep the note at the i-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 characters k 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.

    Sample test(s)
    input
    3 5 1 3
    1 1 2
    2 2 3
    3 3 3
    4 1 1
    10 1 3
    
    output
    XXRR
    就是简单的模拟,如果,可以目标走,就走,不能走就输出X就可以了!
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    using namespace std;
    #define M 100050
    struct node {
        int t,l,r;
    }p[M];
    int m;
    bool find(int x,int a,int b){
        int s=0,e=m-1,mid;
        while(s<=e){
            mid=(s+e)>>1;
            if(p[mid].t==x){
                if((a<p[mid].l||a>p[mid].r)&&(b<p[mid].l||b>p[mid].r))return true;
                else return false;
            }
            else if(p[mid].t<x)
            s=mid+1;
            else if(p[mid].t>x)
            e=mid-1;
        }
        return true;
    }
    int main()
    {
        int n,s,f,i,ans;char c;
        while(scanf("%d%d%d%d",&n,&m,&s,&f)!=EOF){
            if(s<f)c='R',ans=1;
            else c='L',ans=-1;
            for(i=0;i<m;i++){
                scanf("%d%d%d",&p[i].t,&p[i].l,&p[i].r);
            }
            int t=1;
            while(s!=f){
                if(find(t,s,s+ans)) s+=ans,printf("%c",c);
                else printf("X");
                t++;
            }
            printf("
    ");
        }
        return 0;
    }
    


  • 相关阅读:
    js 将内容复制到剪切板上
    javascript刷新父页面的各种方法汇总
    jQuery 使得文本框获得焦点
    layui switch 开关监听 弹出确定状态转换
    layui 图片上传+表单提交+ Spring MVC
    python爬虫实例--网易云音乐排行榜爬虫
    Python爬虫html解析工具beautifulSoup在pycharm中安装及失败的解决办法
    python爬虫实例--博客园首页Java目录博文爬虫
    让js中的函数只有一次有效调用的三种常用方法
    spring项目获取ServletContext
  • 原文地址:https://www.cnblogs.com/riskyer/p/3318184.html
Copyright © 2011-2022 走看看