Codeforces Round #138 (Div. 1), problem: (B) Two Strings
来源:互联网 发布:如何配眼镜知乎 编辑:程序博客网 时间:2024/05/22 00:36
题意:一开始真的是读不懂啊。题意是给定字符串a,b,用b去匹配a,求出所有的匹配子序列之后,判定这些子序列是否可以完全覆盖a。
做法:先求出a字符串中每个字符可以匹配到b中最远的那个字符,然后再倒着求出每个字符的最近匹配...
#include <iostream>#include <cstring>#include <cstdio>/*****先从头开始求出每个s[i]中可以匹配的t中的最末一个字符,然而,这样并不能决定它是否可以完全匹配T,因为不知道后续的字母是否可以补完,所有便又从头开始匹配***/const int LMT=200005;using namespace std;int pos[300],front[LMT],back[LMT];char sec[LMT],tec[LMT];int main(){ scanf("%s%s",&sec[1],&tec[1]); int j=1,l1=strlen(&sec[1]),l2=strlen(&tec[1]); for(int i=1;i<=l1;i++) { if(j<=l2&&sec[i]==tec[j]) { pos[sec[i]]=j; j++; } front[i]=pos[sec[i]]; } memset(pos,0,sizeof(pos)); j=l2; for(int i=l1;i>0;i--) { if(j>0&&sec[i]==tec[j]) { pos[sec[i]]=l2-j+1; j--; } back[i]=pos[sec[i]]; } for(int i=1;i<=l1;i++) if(back[i]+front[i]<=l2) { puts("No"); return 0; } puts("Yes"); return 0;}
- Codeforces Round #138 (Div. 1), problem: (B) Two Strings
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings
- Codeforces Round #FF (Div. 2) Problem B DZY Loves Strings
- Codeforces Round #179 (Div. 2) B (codeforces 296b) Yaroslav and Two Strings
- Codeforces Round #138 (Div. 2)D. Two Strings
- Codeforces Round #210 (Div. 1) problem C Levko and Strings
- Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
- codeforces Round 313 (Div. 1) B.Equivalent Strings
- Codeforces Round #268 (Div. 1)-----B. Two Sets
- Codeforces Round #168 (Div. 1), problem: (B) Zero Tree, DFS
- Codeforces Round #253 (Div. 1) B. Andrey and Problem
- Codeforces Round #296 (Div. 1)B---Clique Problem
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #311 (Div. 2) Problem B
- Codeforces Round #363 (Div. 2), problem: (B)
- CodeForces Round #179 (296B) - Yaroslav and Two Strings
- UVa 10600 ACM contest and Blackout( 次小生成树)
- 汇编中的管道操作方法
- 云计算特点
- JAVA语言编码规范
- c语言中的#ifndef、#def、#endif等宏是什么意思 .
- Codeforces Round #138 (Div. 1), problem: (B) Two Strings
- static 初始化原理
- Ubuntu 12.10解决flash白屏的问题
- android 基础
- 新年捷报频传,感激深深
- android framework
- 安装DEDECMS出现Deprecated: Function ereg_replace() is deprecated in 的原因
- 【堆/优先队列】洗澡 bath
- liujianminghero