Codeforces 615C Running Track 【模拟匹配】
来源:互联网 发布:国内航空英语翻译软件 编辑:程序博客网 时间:2024/06/06 01:23
题意:给你两个字符串s和t,每次你可以从完整的s串中任意截取一段连续的串接上去(接之前可以翻转一下),问你最少需要截取多少次可以构成串t,输出每次截取的起点x和终点y,若x < y说明截取后直接接后面,x > y说明接之前先翻转。
还以为3层时间复杂度会T,一直YY2层的算法。
思路:暴力模拟匹配,正着反着各扫一遍匹配。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#include <string>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (2100+10)#define MAXM (200000+10)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 10007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1#define PI acos(-1.0)using namespace std;char s[MAXN], ss[MAXN], t[MAXN];int ans[MAXN][2];int main(){ Rs(s); Rs(t); strcpy(ss, s); strrev(ss); int ls = strlen(s); int lt = strlen(t); int num = 0; for(int i = 0; i < lt;) { int nextpos = -1; int p1, p2; for(int j = 0; j < ls; j++) { int k = j; int next = i; while(next < lt && s[k] == t[next]) next++, k++; //next--; if(next > nextpos) {nextpos = next, p1 = j+1, p2 = k;} } for(int j = 0; j < ls; j++) { int k = j; int next = i; while(next < lt && ss[k] == t[next]) next++, k++; //next--; if(next > nextpos) {nextpos = next, p1 = ls-j, p2 = ls-k+1;} } if(i == nextpos) {Pi(-1); return 0;} i = nextpos; ans[num][0] = p1, ans[num++][1] = p2; } Pi(num); for(int i = 0; i < num; i++) printf("%d %d\n", ans[i][0], ans[i][1]); return 0;}
0 0
- Codeforces 615C Running Track 【模拟匹配】
- Codeforces 615 C Running Track【KMP匹配】
- CodeForces 615C Running Track【暴力模拟】
- CodeForces 615C Running Track
- Codeforces 615C. Running Track
- CodeForces 615 C. Running Track(贪心)
- codeforces 615 C. Running Track trie + dp
- 【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
- eclispse功能强大插件
- 第一章 Spring概述
- c语言编译常见报错
- struts2整合CXF访问路径冲突问题
- [4]姥爷幽默谈Objective-C-SEL的详细用法(封装方法)
- Codeforces 615C Running Track 【模拟匹配】
- [链表]九度OJ 题目1188:约瑟夫环
- Android Developer:Memory Monitor演示
- 原子性
- UIView的一些知识
- 小林的第一篇博客
- Android Studio中导入依赖库的方法
- SocketChannel的read值为0
- Xcode上传ipa时itunes提示you are not authorized to use this service