神奇(%%题解)

题意:判断B串作为A串的子序列,不是不可以把A全部覆盖掉。

这样的话就是判断是不是A[i]最右匹配B的点和最左匹配B的点相交(重合)就好。(不重合的话B自然会空出中间一段,那么肯定不能用B来做A的子序列了)

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define N 100005
  4. using namespace std;
  5. inline int ra()
  6. {
  7. int x=,f=; char ch=getchar();
  8. while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
  9. while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
  10. return x*f;
  11. }
  12. char s[N<<],t[N<<];
  13. int L[N<<],R[N<<],last[N<<];
  14. int main()
  15. {
  16. scanf("%s%s",s,t);
  17. memset(last,-,sizeof(last));
  18. int j=,slen=strlen(s),tlen=strlen(t);
  19. for (int i=; i<slen; i++)
  20. {
  21. L[i]=last[s[i]-'a'];
  22. if (j<tlen && s[i]==t[j])
  23. {
  24. L[i]=j;
  25. j++;
  26. }
  27. last[s[i]-'a']=L[i];
  28. }
  29. memset(last,-,sizeof(last));
  30. j=tlen-;
  31. for (int i=slen-; i>=; i--)
  32. {
  33. R[i]=last[s[i]-'a'];
  34. if (j>= && s[i]==t[j])
  35. {
  36. R[i]=j;
  37. j--;
  38. }
  39. last[s[i]-'a']=R[i];
  40. }
  41. bool ok=;
  42. for (int i=; i<slen; i++)
  43. if (L[i]==- || R[i]==- || L[i]<R[i])
  44. {
  45. ok=;
  46. break;
  47. }
  48. ok?puts("Yes"):puts("No");
  49. return ;
  50. }

cf 223B.Two Strings的更多相关文章

  1. CF Set of Strings

    Set of Strings time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. CF Vitaly and Strings

    Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. CF 543C Remembering Strings

    https://cn.vjudge.net/problem/CodeForces-543C 题目 You have multiset of n strings of the same length, ...

  4. CF 149E Martian Strings 后缀自动机

    这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...

  5. CF 452E. Three strings(后缀数组+并查集)

    传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次, ...

  6. cf 762C. Two strings

    因为要删去1个串(读错题),所以就直接二分搞就好了. 需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了. #include<bits/stdc++.h> ...

  7. CF数据结构练习

    1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...

  8. CF 1083 B. The Fair Nut and Strings

    B. The Fair Nut and Strings 题目链接 题意: 在给定的字符串a和字符串b中找到最多k个字符串,使得不同的前缀字符串的数量最多. 分析:  建出trie树,给定的两个字符串就 ...

  9. CF#358 D. Alyona and Strings DP

    D. Alyona and Strings 题意 给出两个字符串s,t,让找出最长的k个在s,t不相交的公共子串. 思路 看了好几个题解才搞懂. 代码中有注释 代码 #include<bits/ ...

随机推荐

  1. Day1-D-CF-1144C

    简述:给你一个数组,判断是否能拆分成2个数组,一个递增一个递减,若不行输出No,可以就Yes并分别输出 思路:统计每个数出现的次数,若有大于2的肯定无法组成严格单调,这样就只需要将出现两次的组成递,剩 ...

  2. Java自学-集合框架 HashSet、LinkedHashSet、TreeSet之间的区别

    HashSet. LinkedHashSet.TreeSet之间的区别 步骤 1 : HashSet LinkedHashSet TreeSet HashSet: 无序 LinkedHashSet: ...

  3. 5.5 Nginx 负载均衡

    ip_hash 语法:ip_hash 默认值:none 使用字段:upstream 这个指令将基于客户端连接的IP地址来分发请求.哈希的关键字是客户端的C类网络地址,这个功能将保证这个客户端请求总是被 ...

  4. Lesson 5 Youth

    How does the writer like to treat young people? People are always talking about 'the problem of yout ...

  5. docker 日志清理

    首先确认 docker 使用的存储引擎 docker info 如果使用 Logging Driver: json-file, 那么日志默认在 /var/lib/docker/contains/xxx ...

  6. Jumpserver docker-compose 随手记

    wget  或  git clone   docker  build  -t   jumpserver:v1   .     #构建镜像   docker images vim  jumpserver ...

  7. linux下解决git clone太慢

    此教程同样也适用与vscode下载太慢的问题 git和vscode会自动使用http_proxy,https_proxy环境变量的代理,所以我们只需要设置这个环境变量即可 前提 需要一个可用的代理,这 ...

  8. 合天rev200.exe

    查过之后无壳,查看一下详细信息 运行一下. 猜测可能是输入两个password...拖到ida里面查看,shfit+f12查看 转到此处然后继续查看,找到第一个password通过 一开始时直接输入的 ...

  9. Gym 101158D(暴力)

    题意:给定两个长度为N的字符串,1<=N<=4000,求满足字符串1中的某个区间所有的字母种类和个数都与字符串2中的某个区间相同最长的区间长度. 分析: 1.预处理每个串字母个数的前缀和. ...

  10. 对jsp中的js进行调试的方法

    在js中 输入debugger 就可以了