Codeforces Round #338 (Div. 2) C. Running Track 字符串处理
来源:互联网 发布:淘宝收件人名字大全 编辑:程序博客网 时间:2024/06/01 08:58
题意:给两个字符串s1,s3。s3能否由s1或者s1的反字符串s2的某些连续的部分构成。例:s1 = “abc” s2 = “cbaabc” “cbaabc” = “cba” + “abc”.
思路:暴力就好,首先看”c”能不能在s1或者s2中找到,然后看”cb”能不能在s1或者s2中找到,如果能找到,继续这个过程。如果不能找到,”c”就是一个结果,”b”就是下一个字符串的第一个字符。
http://codeforces.com/contest/615/problem/C
/********************************************* Problem : Codeforces Author : NMfloat InkTime (c) NM . All Rights Reserved .********************************************/#include <map>#include <set>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i ++) //遍历#define rrep(i,a,b) for(int i = (b) ; i >= (a) ; i --) //反向遍历#define repS(it,p) for(auto it = p.begin() ; it != p.end() ; it ++) //遍历一个STL容器#define repE(p,u) for(Edge * p = G[u].first ; p ; p = p -> next) //遍历u所连接的点#define cls(a,x) memset(a,x,sizeof(a))#define eps 1e-8using namespace std;const int MOD = 1e9+7;const int INF = 0x3f3f3f3f;const int MAXN = 1e5+5;const int MAXE = 2e5+5;typedef long long LL;typedef unsigned long long ULL;int T,n,m,k;int fx[] = {0,1,-1,0,0};int fy[] = {0,0,0,-1,1};char s1[2105],s2[2105],s3[2105];char tmp[2105];int lens ;void get_s2() { rep(i,0,lens-1) { s2[lens-i-1] = s1[i]; } s2[lens] = 0;}void input() {}int pos1 = 0 , pos2 = 0;int prepos1 , prepos2;int par[2105][2];int pos = 0;void get_pos() { prepos1 = pos1 ; prepos2 = pos2 ; if(pos > lens) { pos1 = pos2 = -1; return ; } pos1 = strstr(s1,tmp) - s1; pos2 = strstr(s2,tmp) - s2;} void solve() { lens = strlen(s1); get_s2(); int len = strlen(s3); int tot = 0; pos1 = -1 ; pos2 = -1; pos = 0; int ok = 0; s3[len] = '#'; rep(i,0,len) { tmp[pos++] = s3[i]; tmp[pos] = 0; get_pos(); if(pos1 >= 0 || pos2 >= 0) { } else { ++ tot; if(prepos1 < 0 && prepos2 <0) { ok = 1; break; } if(prepos1 >= 0) { par[tot][0] = prepos1 + 1; par[tot][1] = prepos1 + strlen(tmp) - 1; } else { par[tot][0] = lens - prepos2 ; par[tot][1] = lens - prepos2 - strlen(tmp) + 2; } pos = 0; tmp[pos++] = s3[i]; tmp[pos] = 0; get_pos(); } } if(!ok) { printf("%d\n",tot); rep(i,1,tot) { printf("%d %d\n",par[i][0],par[i][1]); } } else { puts("-1"); }}int main(void) { //freopen("a.in","r",stdin); while(~scanf("%s%s",s1,s3)) { input(); solve(); } return 0;}
0 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 Round #173 (Div. 2) / 282C XOR and OR (字符串处理)
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 字符串处理
- CDATA区段的作用
- adb devices连接提示 Android offline或unauthorized的解决办法
- Algorithm Intro - Merge Sort
- Java反射
- 菜鸟学python(7) 简单文件访问
- Codeforces Round #338 (Div. 2) C. Running Track 字符串处理
- 使用包含预定义动作的隐式Intent
- Sicily 1500. Prime Gap
- C++入门(12):高级OOP技术:重载操作符、多继承和虚继承
- SpringMVC在做静态资源映射的时候需要注意的问题
- 注解
- 12 蛇形打印矩阵中的数据
- Algorithm Intro - Quick Sort
- 将自己的rest web app 从内网发布到外网