Codeforces Round #579 (Div. 3)D(字符串,思维)
#include<bits/stdc++.h>
using namespace std;
char s[200007],t[200007];
int last[200007][27],nxt[200007][27];
int l[200007],r[200007];
int main(){
cin>>s+1>>t+1;
int n=strlen(s+1);
int m=strlen(t+1);
for(int i=1;i<=n;++i){
for(int j=0;j<26;++j)
last[i][j]=last[i-1][j];//i表示当前位置,j表示字母大小,复制当前位置以前最晚出现字母j的位置就是前一格位置以前最晚出现j字母的位置
last[i][s[i]-'a']=i;//更新当前位置以前最晚出现字母s[i]的位置
}
for(int i=n;i;--i){
for(int j=0;j<26;++j)
nxt[i][j]=nxt[i+1][j];//复制当前位置以后最早出现字母j的位置就是前一格位置以前最早出现字母j的位置
nxt[i][s[i]-'a']=i;//更新当前位置以后最早出现字母s[i]的位置
}
int now=1;
l[0]=1;
for(int i=1;i<=m;++i){
now=nxt[now][t[i]-'a']+1;//now表示now位置以后最早出现字母t[i]的位置,保证该位置以后还能有剩余的t字符串i+1~m
l[i]=now;//更新i位置左端点的值为now
}
now=n;
r[m+1]=n;
for(int i=m;i;--i){
now=last[now][t[i]-'a']-1;//now表示now位置以前最晚出现字母t[i]的位置,保证该位置以前还能有剩余的t字符串1~i-1
r[i]=now;//更新i位置右端点的值为now
}
int ans=0;
for(int i=0;i<=m;++i)
ans=max(r[i+1]-l[i]+1,ans);//更新答案为字母t[i+1]最晚出现的位置减去字母t[i]最早出现的位置+1
cout<<ans;
return 0;
}
Codeforces Round #579 (Div. 3)D(字符串,思维)的更多相关文章
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
- Codeforces Round #579 (Div. 3)
Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】
A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:sta ...
- Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)
题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...
- 【cf比赛练习记录】Codeforces Round #579 (Div. 3)
思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Circle of Students 题意 给出n个数,问它们向左或者向右是否都能成一个环.比如样例5是从1开始向左绕了一圈 [3, 2, 1, ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #329 (Div. 2)A 字符串处理
A. 2Char time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
随机推荐
- ARM64架构下登录mysql出错:mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file:
Linux下登录mysql出错:mysql: error while loading shared libraries: libncurses.so.5: cannot open shared obj ...
- Flask 学习之flask入门
一.Flask的简单介绍 Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收http请 ...
- python中 使用join()方法
使用join()方法 对各种数据类型中元的素进行合并拼接 "连接符".join(列表或元组或字符串或字典) 返回的是一个使用连接符进行拼接的字符串 如果对象是列表,元组,就是以一个 ...
- css3的一些特效
前段时间有位同事分享了一个网站,里边是一些css3特效,看着挺好,分享一下: [http://daneden.github.io/animate.css/ ] 所有的特效都集中在一个css层叠样式表中 ...
- 20180923-WebService
什么是webservice? 什么是远程调用技术?答:系统和系统之间的调用,从远程系统当中获取业务数据. Webservice是web服务,他是用http传输SOAP协议数据的一种远程调用 ...
- tkinter+pickle+python的一个登录界面设计
1.代码: #导出模块 import tkinter as tk from tkinter import messagebox import pickle #定义登录的窗口.标题.大小和位置 wind ...
- 《深入理解Java虚拟机》读书笔记四
第五章 调优案例分析与实战
- netty笔记-:EpollEventLoopGroup:Caused by: java.lang.ExceptionInInitializerError:Caused by: java.lang.IllegalStateException: Only supported on Linux
今天在翻看netty的源码的时候发现netty对EventLoopGroup的实现有不止常用的NIOEventLoopGroup ,一共有以下几种. EpollEventLoopGroup NioEv ...
- 提高Scrapy爬取效率
1.增加并发: 默认scrapy开启的并发线程为32个,可以适当进行增加.在settings配置文件中修改CONCURRENT_REQUESTS = 100值为100,并发设置成了为100. 2.降低 ...
- 《TCP/IP网络编程》读书笔记
1.Windows 下的 socket 程序和 Linux 思路相同,但细节有所差别(1) Windows 下的 socket 程序依赖 Winsock.dll 或 ws2_32.dll,必须提前加载 ...