CodeForces 615C Running Track【暴力模拟】
来源:互联网 发布:淘宝网店推广方法 编辑:程序博客网 时间:2024/06/05 12:42
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".
将所给的串反转,所求串分别与正串,反串比较,选择最优的记录
#include <iostream>#include<cstdio>#include<cstring>#define maxn 2200using namespace std;int main(){ char str[maxn],buf[maxn],tem[maxn]; int ans[2][maxn]; while(~scanf("%s%s",str,buf)) { strcpy(tem,str); strrev(tem); int lens=strlen(str); int lenb=strlen(buf); memset(ans,0,sizeof(ans)); int s=0,mark=0,p1,p2; for(int i=0;i<lenb;) { for(int j=0;j<lens;++j) { int k=i,t=j; while(str[t]==buf[k]&&t<lens&&k<lenb) k++,t++; if(k>mark) { mark=k; p1=j+1; p2=t; } } for(int j=0;j<lens;++j) { int k=i,t=j; while(tem[t]==buf[k]&&t<lens&&k<lenb) t++,k++; if(k>mark) mark=k,p1=lens-j,p2=lens-t+1; } if(mark==i) { printf("-1\n"); s=0; break; } i=mark; ans[0][s]=p1; ans[1][s++]=p2; } if(s) printf("%d\n",s); for(int i=0;i<s;++i) printf("%d %d\n",ans[0][i],ans[1][i]); } return 0;}
- 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 Round #338 (Div. 2) 615C Running Track(dp)
- Codeforces 615C Running Track (Round #338 (Div. 2) C题) Trie + 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 Round #338 (Div. 2) C. Running Track(DP)
- Codeforces Round #338 (Div. 2)C. Running Track
- 615A Running Track
- Codeforces Round #338 (Div. 2) C. Running Track(dp + kmp)
- Codeforces 166C Median 暴力模拟
- 服装标准中纰裂试验方法的比较与探讨
- Leetcode之Next Permutation (Medium)
- Oracle数据迁移至HBase操作记录
- Java I/O系统
- C语言使用可变参数函数
- CodeForces 615C Running Track【暴力模拟】
- 实验5-5 使用函数求素数和 (20分)
- Xcode7HTTP请求以及真机调试
- STL容器介绍
- 网络编程归纳总结四阶段
- 深入分析JavaWeb Item51 -- Spring依赖注入
- iframe 调用Servlet 更改 父页面的url
- bitset查找质数
- jQuery网页背景灯光闪烁特效