CodeForces 615C Running Track
来源:互联网 发布:旧版安卓软件 编辑:程序博客网 时间:2024/06/05 18:16
题意:给一个S串,再给一个T串,问怎么用S串里面的子串合成T串,S串里面的子串可以翻转
思路:暴力一发….
#include<bits/stdc++.h>using namespace std;const int maxn = 2100;char a[maxn],b[maxn],c[maxn];int x[maxn],y[maxn];int main(){ scanf("%s%s",a,c); int len1 = strlen(a); for (int i = 0;i<len1;i++) b[i]=a[len1-i-1]; int len2 = strlen(c); int ans = 0; for (int i = 0;i<len2;i++) { int flag=0; int xx,yy; for (int j = 0;j<len1;j++) { if (c[i]==a[j]) { int k = i; int h = j; while (c[k]==a[h]&&k<len2&&h<len1) { k++; h++; } int l = k-i; if (flag<l) { flag=l; xx=j+1; yy=j+l; } } } for (int j = 0;j<len1;j++) { if (c[i]==b[j]) { int k = i; int h = j; while (c[k]==b[h]&&k<len2&&h<len1) { k++; h++; } int l = k-i; if (flag<l) { flag=l; xx=len1-j; yy=len1-(j+l-1); } } } if (flag) { x[ans]=xx; y[ans]=yy; ans++; i+=(flag-1); } else { ans=0; break; } } if (ans==0) { printf("-1\n"); return 0; } printf("%d\n",ans); for (int i = 0;i<ans;i++) printf("%d %d\n",x[i],y[i]);}
Description
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 Input
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
Hint
In the first sample string “cbaabc” = “cba” + “abc”.
In the second sample: “ayrat” = “a” + “yr” + “at”.
- 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)
- Running Track
- LeetCode341 Flatten Nested List Iterator(迭代器模式实践) Java
- javascript设计模式与开发实践--学习笔记一
- <Android 应用 之路> 简易贪吃蛇
- Spring框架AOP的配置和实现的简单例子
- 低价购买(动规例题)
- CodeForces 615C Running Track
- CEP的一个简单理解
- ubuntu基本操作
- 关于android蓝牙通信那点事
- I. Permutations
- POJ 2686 Traveling by Stagecoach
- 类 ApplicationInfo详解
- 检查一颗二叉树是否是二叉查找树
- Python @classmethod和@staticmethod区别