Codeforces Round #338 (Div. 2)C. Running Track
来源:互联网 发布:yy淘宝客服兼职靠谱吗 编辑:程序博客网 时间:2024/05/16 17:01
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.
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.
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.
abccbaabc
23 11 3
aaabrytaaaayrat
31 16 58 7
amino
-1
In the first sample string "cbaabc" = "cba" + "abc".
In the second sample: "ayrat" = "a" + "yr" + "at".
/* ***********************************************Author : rycCreated Time : 2016-08-11 ThursdayFile Name : E:\acm\codeforces\338C.cppLanguage : c++Copyright 2016 ryc All Rights Reserved************************************************ */#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<vector>#include<map>#include<stack>using namespace std;const int maxn=3010;char s[maxn];char str[maxn];char s1[maxn];char temp[maxn];bool vis[maxn];struct Node{ int l,r;}ans[maxn];int main(){ scanf("%s%s",s+1,str+1); int len1=strlen(s+1); int len2=strlen(str+1); for(int i=1;s[i];++i){ vis[s[i]-'a']=true; s1[len1-i+1]=s[i]; } for(int i=1;str[i];++i){ if(!vis[str[i]-'a']){ printf("-1\n"); return 0; } }s1[len1+1]=0; int num=0; for(int i=1;i<=len2;++i){ int cnt1=0,l1,l2,cnt2=0;bool sign=false; for(int j=i;j<=len2;++j){ temp[cnt1++]=str[j];temp[cnt1]=0; if(strstr(s+1,temp)){ cnt2=cnt1; l1=strstr(s+1,temp)-s; } else { if(strstr(s1+1,temp)){ sign=true;cnt2=cnt1; l2=strstr(s1+1,temp)-s1; } else break; } } if(sign){ ans[num].l=len1-l2+1;ans[num].r=(len1-l2+1)-cnt2+1;num++; } else { ans[num].l=l1;ans[num].r=l1+cnt2-1;num++; } i=i+cnt2-1; } printf("%d\n",num); for(int i=0;i<num;++i){ printf("%d %d\n",ans[i].l,ans[i].r); } return 0;}
- Codeforces Round #338 (Div. 2) C. Running Track 字符串处理
- Codeforces Round #338 (Div. 2) 615C Running Track(dp)
- Codeforces Round #338 (Div. 2) C. Running Track (dp)
- Codeforces Round #338 (Div. 2) C. Running Track
- Codeforces Round #338 (Div. 2) C. Running Track(DP)
- Codeforces Round #338 (Div. 2)C. Running Track
- Codeforces 615C Running Track (Round #338 (Div. 2) C题) Trie + dp
- Codeforces Round #338 (Div. 2) C. Running Track(dp + kmp)
- CodeForces 615C Running Track
- Codeforces 615C. Running Track
- Codeforces 615C Running Track 【模拟匹配】
- CodeForces 615C Running Track【暴力模拟】
- CodeForces 615 C. Running Track(贪心)
- codeforces 615 C. Running Track trie + dp
- Codeforces 615 C Running Track【KMP匹配】
- 【28.57%】【codeforces 615C】 Running Track
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #338 (Div. 2)
- 使用Genymotion安装APK出现错误Failure [INSTALL_FAILED_NO_MATCHING_ABIS]解决办法
- Activity四种启动模式
- shiro 框架使用实例
- C++ const
- C3P0、DBCP、Tomcat JDBC Pool 连接池区别(推荐使用JDBC Pool)
- Codeforces Round #338 (Div. 2)C. Running Track
- ACM 计算几何知识点总结 详解
- 泛型基础用法解析
- Android学习笔记02——浏览手机中的文件夹
- ACDream 1071 神奇的%系列一
- NoSQLAttack - MongoDB默认配置攻击和注入攻击工具
- 2016.08.11【初中部 NOIP提高组 】模拟赛C题解
- Stars(树状数组)
- IntentService