zoukankan      html  css  js  c++  java
  • codeforces 615C Running Track

    C. Running Track

     

    A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art.

    First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string.

    Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer.

    Input

    First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100.

    Output

    The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating.

    If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t.

    Sample test(s)
    input
    abc
    cbaabc
    output
    2
    3 1
    1 3
    input
    aaabrytaaa
    ayrat
    output
    3
    1 1
    6 5
    8 7
    input
    ami
    no
    output
    -1
    Note

    In the first sample string "cbaabc" = "cba" + "abc".

    In the second sample: "ayrat" = "a" + "yr" + "at".

    #include<cstdio>
    #include<cstring>
    #include<stack>
    #include<vector>
    #include<iostream>
    #include<map>
    #include<string>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    char s[2][2105];
    int len[2],st,ed,maxlen,l;
    vector<int>let[26];
    vector<pair<int,int> >ans;
    bool vis[2105];
    void dfs(int cur,int pos)
    {
        if(cur>=maxlen)st=l,ed=pos,maxlen=cur;
        if(cur==len[1])return;
        if(pos&&s[0][pos-1]==s[1][cur+1]&&!vis[pos-1])
            vis[pos-1]=1,dfs(cur+1,pos-1),vis[pos-1]=0;
        if(pos+1<len[0]&&s[0][pos+1]==s[1][cur+1]&&!vis[pos+1])
            vis[pos+1]=1,dfs(cur+1,pos+1),vis[pos+1]=0;
    }
    int main()
    {
        int i;
        for(i=0;i<2;i++)
        {
            scanf("%s",s[i]);
            len[i]=strlen(s[i]);
        }
        for(i=0;i<len[0];i++)
            let[s[0][i]-'a'].push_back(i);
        for(i=0;i<len[1];i++)
        {
            int n=let[s[1][i]-'a'].size();
            if(!n)break;
            maxlen=i;
            for(int j=0;j<n;j++)
            {
                memset(vis,0,sizeof(vis));
                l=let[s[1][i]-'a'][j];
                vis[l]=1;
                dfs(i,let[s[1][i]-'a'][j]);
            }
            i=maxlen;
            ans.push_back(make_pair(st+1,ed+1));
        }
        if(i<len[1])
            puts("-1");
        else
        {
            int n=ans.size();
            printf("%d
    ",n);
            for(i=0;i<n;i++)
                cout<<ans[i].first<<" "<<ans[i].second<<endl;
        }
        return 0;
    }
  • 相关阅读:
    4步搞定:系统必备的安装位置未设置为组件供应商的网站,无法在磁盘上找到 dotNetFx40LP_Client_x86_x64cs.exe 问题的解决方案 VS2010 SP1 简体中文测试通过,繁体未测试
    SilverLight Expression 140小时视频讲座
    获取本地IP铁通也可以
    USB转485转换器
    继电器控制板
    远程抄表解决方案汇总
    Silverlight 鼠标滚轮组件“Silverlight.FX”
    Silverlight边学边写之一“Silverlight+Webservice+Dataset”综合应用
    企业库缓存类(EnterpriseLibrary CacheHelper )
    Silverlight Toolkit 正式版今天发布啦!
  • 原文地址:https://www.cnblogs.com/homura/p/5122371.html
Copyright © 2011-2022 走看看