zoukankan      html  css  js  c++  java
  • Codeforce 239 B. Easy Tape Programming

    There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts.

    • Current character pointer (CP);
    • Direction pointer (DP) which can point left or right;

    Initially CP points to the leftmost character of the sequence and DP points to the right.

    We repeat the following steps until the first moment that CP points to somewhere outside the sequence.

    • If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one.
    • If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence.

    If at any moment the CP goes outside of the sequence the execution is terminated.

    It's obvious the every program in this language terminates after some steps.

    We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language.

    Input

    The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries.

    The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces.

    The next q lines each contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the i-th query.

    Output

    For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.

    Examples
    input
    7 4
    1>3>22<
    1 3
    4 7
    7 7
    1 7
    output
    0 1 0 1 0 0 0 0 0 0 
    2 2 2 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    2 3 2 1 0 0 0 0 0 0

    这是一道模拟题,模拟一个他叙述的过程就是一个指针一个方向标记遇到>改成向右的方向,遇见<改成向左,每次遇到数字输出数字并将数字减一,减到零就删去,遇到连续的两个方向就删去先访问的那一个,给定一个子区间,求0-9输出了几遍。
    #include<bits/stdc++.h>
    #define Swap(a,b) a^=b^=a^=b
    #define cini(n) scanf("%d",&n)
    #define cinl(n) scanf("%lld",&n)
    #define cinc(n) scanf("%c",&n)
    #define coui(n) printf("%d",n)
    #define couc(n) printf("%c",n)
    #define coul(n) printf("%lld",n)
    #define speed ios_base::sync_with_stdio(0);//切不可用scnaf;
    #define Max(a,b) a>b?a:b
    #define Min(a,b) a<b?a:b
    using namespace std;
    typedef long long ll;
    const int INF=0x3f3f3f3f;
    const int maxn=1e6+10;
    const double esp=1e-9;
    int m,n,x,y,lll[maxn],rr[maxn];
    int l[110];
    int r[110];
    int ans[10];
    string w;
    int a[10];
    
    int main()
    {
        cin>>n>>m>>w;
        while(m--)
        {
            int l,r;
            cin>>l>>r;
            memset(a,0,sizeof(a));
            string t=w.substr(l-1,r-l+1);
            int lll=0,rr=1;
            int E=t.size();
            while(lll>=0&&lll<E)
            {
                if(t[lll]>='0'&&t[lll]<='9')
                {
                    a[t[lll]-'0']++;
                    t[lll]--;
                    if(t[lll]<'0')
                    {
                        t.erase(lll,1);
                        if(rr<0)lll+=rr;
                    }
                    else  lll+=rr;
                }
                else
                {
                    if(t[lll]=='<') rr=-1;
                    else rr=1;
                    if(lll+rr>=0&&lll+rr<E&&(t[lll+rr]=='<'||t[lll+rr]=='>'))
                    {
                        t.erase(lll,1);
                        if(rr<0) lll+=rr;
                    }
                    else lll+=rr;
                }
            }
            for(int i=0;i<10; i++)
                cout<<a[i]<<' ';
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    安防视频监控直播的画面都是如何采集的?
    为什么说线上教育是未来的趋势?
    音视频流媒体服务器发展到现在有哪些难题?应该怎么解决?
    为什么流媒体服务器做安防视频直播或者娱乐直播服务?
    视频流媒体服务器如何将视频直播转推到其他平台?
    线上教育课堂如何解决H5视频点播转码出现的黑屏问题?
    海康摄像头以GB28181国标协议接入国标流媒体服务器流断码问题的解决办法
    国标GB28181协议流媒体视频平台EasyGBS如何将内网的摄像机视频推送到公网?
    网页全终端视频流媒体播放器EasyPlayer之使用 nginx 和 rtmp 插件搭建视频直播和点播服务器
    安防音视频流媒体服务器EasyDSS之编解码的基本原理及压缩编码的方法介绍
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/11312754.html
Copyright © 2011-2022 走看看