• codeforces412A


    Poster

     CodeForces - 412A 

    The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.

    The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.

    Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.

    Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!

    Input

    The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.

    Output

    In t lines, print the actions the programmers need to make. In the i-th line print:

    • "LEFT" (without the quotes), if the i-th action was "move the ladder to the left";
    • "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right";
    • "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder".

    The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.

    Examples

    Input
    2 2
    R1
    Output
    PRINT 1
    LEFT
    PRINT R
    Input
    2 1
    R1
    Output
    PRINT R
    RIGHT
    PRINT 1
    Input
    6 4
    GO?GO!
    Output
    RIGHT
    RIGHT
    PRINT !
    LEFT
    PRINT O
    LEFT
    PRINT G
    LEFT
    PRINT ?
    LEFT
    PRINT O
    LEFT
    PRINT G

    Note

    Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.

    sol:无脑模拟即可

    #include <bits/stdc++.h>
    using namespace std;
    typedef int ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0'); return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=105;
    int n,m;
    char S[N];
    int main()
    {
        int i;
        R(n); R(m);
        scanf("%s",S+1);
        if(m-1<n-m)
        {
            for(i=1;i<m;i++) puts("LEFT");
            for(i=1;i<n;i++)
            {
                cout<<"PRINT "; putchar(S[i]); putchar('
    '); puts("RIGHT");
            }
            cout<<"PRINT "; putchar(S[n]);
        }
        else
        {
            for(i=m;i<n;i++) puts("RIGHT");
            for(i=n;i>1;i--)
            {
                cout<<"PRINT "; putchar(S[i]); putchar('
    '); puts("LEFT");
            }
            cout<<"PRINT "; putchar(S[1]);
        }
        return 0;
    }
    /*
    Input
    2 2
    R1
    Output
    PRINT 1
    LEFT
    PRINT R
    
    Input
    2 1
    R1
    Output
    PRINT R
    RIGHT
    PRINT 1
    
    Input
    6 4
    GO?GO!
    Output
    RIGHT
    RIGHT
    PRINT !
    LEFT
    PRINT O
    LEFT
    PRINT G
    LEFT
    PRINT ?
    LEFT
    PRINT O
    LEFT
    PRINT G
    */
    View Code
  • 相关阅读:
    PNG背景透明问题
    多文件上传
    Silverlight+WCF 新手实例 象棋 游戏房间列表(十三)
    Silverlight+WCF 新手实例 象棋 房间状态更新(二十)
    Silverlight+WCF 新手实例 象棋 WCF通讯基础(十四)
    Silverlight+WCF 新手实例 象棋 登陆与转向(十一)
    Silverlight+WCF 新手实例 象棋 回归WCF通讯应用登陆(十八)
    Silverlight+WCF 新手实例 象棋 棋子移动吃子(五)
    Silverlight+WCF 新手实例 象棋 游戏房间(十二)
    Silverlight+WCF 新手实例 象棋 棋子移动规则[附加上半盘限制](十)
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/11147517.html
Copyright © 2020-2023  润新知