题目链接:https://codeforces.com/contest/1203/problem/D2

题意:

给你S串、T串,问你最长删除多长的子串使得S串里仍然有T的子序列。

思路:

想了好久,先正着跑一下S串,记录T串每一个字符最左边在哪里,再倒着跑一下,记录T串的每一个字符最右边在哪里。

最后跑一下答案:

1. 开头和结尾特判一下,但不是max( L[1]-1 , l1-R[l2] ) , 而是对两个max( L[1]-1 , l1-L[l2]-1 )、max( R[1]-1 , l1-R[l2]-1 )再取max。

2. 对于中间部分:R[i]-L[i-1]-1 。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>
#include <bitset>
//#include <map>
//#include<unordered_map> https://codeforces.com/contest/1203/problem/D2
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int L[N],R[N];
char s[N],t[N]; int main()
{
// freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
int l1,l2;
s[]=t[]='$';
// while(sc("%s%s",s+1,t+1)==2)
// {
sc("%s%s",s+,t+);
l1=strlen(s)-;
l2=strlen(t)-;
for(int i=,pos=;i<=l1&&pos<=l2;++i)
{
if(t[pos]==s[i])
L[pos]=i,pos++;
}
for(int i=l1,pos=l2;i>=&&pos>=;--i)
{
if(t[pos]==s[i])
R[pos]=i,pos--;
}
int ans=;
ans=maxx(ans,maxx(L[]-,R[]-));
ans=maxx(ans,maxx(l1-L[l2],l1-R[l2]));
for(int i=;i<=l2;++i)
ans=maxx(ans,R[i]-L[i-]-);
pr("%d\n",ans);
// }
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

双指针(最大删除子串)Codeforces Round #579 (Div. 3)--Remove the Substring (hard version)的更多相关文章

  1. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version)

    传送门 题意: 给你一个长为n的仅由'R','G','B'构成的字符串s,你需要在其中找出来一个子串.使得这个子串在"RGBRGBRGBRGB........(以RGB为循环节,我们称这个串 ...

  2. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题

    D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...

  3. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 【递推】

    一.题目 D2. RGB Substring (hard version) 二.分析 思路一开始就想的对的,但是,用memset给数组初始化为0超时了!超时了! 然后我按照题解改了个vector初始化 ...

  4. Codeforces Round #579 (Div. 3)

    Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...

  5. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  6. Codeforces Round #579 (Div. 3) 题解

    比赛链接:https://codeforc.es/contest/1203/ A. Circle of Students 题意:\(T\)组询问,每组询问给出\(n\)个数字,问这\(n\)个数字能否 ...

  7. 【cf比赛练习记录】Codeforces Round #579 (Div. 3)

    思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Circle of Students 题意 给出n个数,问它们向左或者向右是否都能成一个环.比如样例5是从1开始向左绕了一圈 [3, 2, 1, ...

  8. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

  9. Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)

    题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...

随机推荐

  1. codeforces412A

    Poster CodeForces - 412A The R1 company has recently bought a high rise building in the centre of Mo ...

  2. 3.开始使用Spring Cloud实战微服务

                     开始使用Spring Cloud实战微服务 3.1. Spring Cloud实战前提 3.1.1. 需要的技术储备 语言方面:可以使用Java.scala.Groo ...

  3. Javascript引擎的单线程机制和setTimeout执行原理阐述

    工作中使用setTimeout解决了一个问题,于是对setTimeout的相关资料整理了下,以及对js引擎执行的原理一并整理了下,希望能给码农们一些帮助.若发现有错的地方大家及时指出,共同学习进步. ...

  4. JS基础_原型对象

    原型prototype 我们创建的每一个函数,解析器都会向函数中添加一个属性prototype 这个属性,对应着一个对象,这个对象就是我们所谓的原型对象 1.如果函数作为普通函数调用prototype ...

  5. Java如何对一个对象进行深拷贝?

    在Java语言里,当我们需要拷贝一个对象时,有两种类型的拷贝:浅拷贝与深拷贝.浅拷贝只是拷贝了源对象的地址,所以源对象的值发生变化时,拷贝对象的值也会发生变化.而深拷贝则是拷贝了源对象的所有值,所以即 ...

  6. SpringSecurity remember-me功能

    1./login .and().formLogin().loginPage("/user/login.html") //在successHandler中,使用response返回登 ...

  7. 【.net core 0基础】创建你的第一个.net core应用

    1.下载.NET core相应的SDK,https://dotnet.microsoft.com/download 2.安装完成后,打开命令提示符,输入命令 dotnet,检查是否正确安装,如果命令能 ...

  8. openMP---第一篇

    openMP 处理for循环 ///////////////////////////////////////////////////////////////////////////////////// ...

  9. Node JS复制文件

    /** * Created by Administrator on 2019/11/6. *指尖敲打着世界 ----一个阳光而又不失帅气的少年!!!. */ var fs=require(" ...

  10. vue 默认展开详情页

    { path: '/Tree', component: Tree, children: [ { path: '/', component: Come } ] }