cf 223B.Two Strings
神奇(%%题解)
题意:判断B串作为A串的子序列,不是不可以把A全部覆盖掉。
这样的话就是判断是不是A[i]最右匹配B的点和最左匹配B的点相交(重合)就好。(不重合的话B自然会空出中间一段,那么肯定不能用B来做A的子序列了)
#include<bits/stdc++.h>
#define LL long long
#define N 100005
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
char s[N<<],t[N<<];
int L[N<<],R[N<<],last[N<<];
int main()
{
scanf("%s%s",s,t);
memset(last,-,sizeof(last));
int j=,slen=strlen(s),tlen=strlen(t);
for (int i=; i<slen; i++)
{
L[i]=last[s[i]-'a'];
if (j<tlen && s[i]==t[j])
{
L[i]=j;
j++;
}
last[s[i]-'a']=L[i];
}
memset(last,-,sizeof(last));
j=tlen-;
for (int i=slen-; i>=; i--)
{
R[i]=last[s[i]-'a'];
if (j>= && s[i]==t[j])
{
R[i]=j;
j--;
}
last[s[i]-'a']=R[i];
}
bool ok=;
for (int i=; i<slen; i++)
if (L[i]==- || R[i]==- || L[i]<R[i])
{
ok=;
break;
}
ok?puts("Yes"):puts("No");
return ;
}
cf 223B.Two Strings的更多相关文章
- CF Set of Strings
Set of Strings time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF Vitaly and Strings
Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CF 543C Remembering Strings
https://cn.vjudge.net/problem/CodeForces-543C 题目 You have multiset of n strings of the same length, ...
- CF 149E Martian Strings 后缀自动机
这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...
- CF 452E. Three strings(后缀数组+并查集)
传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次, ...
- cf 762C. Two strings
因为要删去1个串(读错题),所以就直接二分搞就好了. 需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了. #include<bits/stdc++.h> ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- CF 1083 B. The Fair Nut and Strings
B. The Fair Nut and Strings 题目链接 题意: 在给定的字符串a和字符串b中找到最多k个字符串,使得不同的前缀字符串的数量最多. 分析: 建出trie树,给定的两个字符串就 ...
- CF#358 D. Alyona and Strings DP
D. Alyona and Strings 题意 给出两个字符串s,t,让找出最长的k个在s,t不相交的公共子串. 思路 看了好几个题解才搞懂. 代码中有注释 代码 #include<bits/ ...
随机推荐
- SpringBoot 静态资源的配置
springboot默认的静态资源目录: classpath:/static classpath:/public classpath:/resources classpath:/META-INF/re ...
- IdentityServer4专题之三:OAuth、SSO和OpenID
一.oauth 典型案例:如果一个用户R拥有两项服务:一项服务是图片在线存储服务A,另一个是图片在线打印服务B.由于服务A与服务B是由两家不同的服务提供商提供的,所以用户在这两家服务提供商的网站上各自 ...
- vb.net导出CSV文件
Public Function WriteToCSV(ByVal dataTable As DataTable, ByVal filePath As String, ByVal records As ...
- DevOps - 总结
章节 DevOps – 为什么 DevOps – 与传统方式区别 DevOps – 优势 DevOps – 不适用 DevOps – 生命周期 DevOps – 与敏捷方法区别 DevOps – 实施 ...
- JAVA 发送各种邮箱邮件 javamail
QQ邮箱 /** * 单条发送 * @param mail 邮件对象,包含发送人.邮件主题.邮件内容 * @param recipients 收件人 * @throws AddressExceptio ...
- P1070 结绳
P1070 结绳 转跳点:
- PHP截取指定字符前的字符串
$str = 'A|B||C|D'; echo substr($str,0,strpos($str, '||')); 输出:A|B
- JDK8~JDK11的新特性
#JDK 1.8 新特性接口中的静态方法 只能由接口自己调用 接口中的默认方法 可以不被覆盖 #JDK 1.9 新特性(可能在JDK8中被忽略了,没来得及加)接口可以定义私有方法,但是只能让自己调用, ...
- solus linux 更新源
添加源(清华大学开源软件镜像)sudo eopkg ar Solus https://mirrors.tuna.tsinghua.edu.cn/solus/shannon/eopkg-index.xm ...
- 2018年第九届蓝桥杯【C++省赛B组】(未完)
第一题 标题:第几天 2000年的1月1日,是那一年的第1天. 那么,2000年的5月4日,是那一年的第几天? 注意:需要提交的是一个整数,不要填写任何多余内容 利用excel更加快捷: 答案是125 ...