双指针(最大删除子串)Codeforces Round #579 (Div. 3)--Remove the Substring (hard version)
题目链接: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)的更多相关文章
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version)
传送门 题意: 给你一个长为n的仅由'R','G','B'构成的字符串s,你需要在其中找出来一个子串.使得这个子串在"RGBRGBRGBRGB........(以RGB为循环节,我们称这个串 ...
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题
D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 【递推】
一.题目 D2. RGB Substring (hard version) 二.分析 思路一开始就想的对的,但是,用memset给数组初始化为0超时了!超时了! 然后我按照题解改了个vector初始化 ...
- Codeforces Round #579 (Div. 3)
Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #579 (Div. 3) 题解
比赛链接:https://codeforc.es/contest/1203/ A. Circle of Students 题意:\(T\)组询问,每组询问给出\(n\)个数字,问这\(n\)个数字能否 ...
- 【cf比赛练习记录】Codeforces Round #579 (Div. 3)
思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Circle of Students 题意 给出n个数,问它们向左或者向右是否都能成一个环.比如样例5是从1开始向左绕了一圈 [3, 2, 1, ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
- Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)
题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...
随机推荐
- 推荐系统系列(四):PNN理论与实践
背景 上一篇文章介绍了FNN [2],在FM的基础上引入了DNN对特征进行高阶组合提高模型表现.但FNN并不是完美的,针对FNN的缺点上交与UCL于2016年联合提出一种新的改进模型PNN(Produ ...
- nagios监控部署
nagios监控部署. 在部署之前把依赖包安装了. [root@tiandong63 ~]# yum install -y gcc glibc glibc-common php gd gd-devel ...
- [CSP-S模拟测试]:慢无止境的八月(乱搞)
题目传送门(内部题102) 输入格式 第一行三个正整数$n,k,q$,分别表示数列长度,操作长度和修改个数. 第二行$n$个数,表示给出的终止数列. 接下来$q$行,每行两个数$pos,dx$,表示将 ...
- CentOS修改Mysql字符集
1.mysql>show variables like 'character_set%'; 显示如下: +--------------------------+----------------- ...
- TCP被动打开 之 第一次握手-接收SYN
假定客户端执行主动打开,服务器执行被动打开,客户端发送syn包到服务器,服务器接收该包,进行建立连接请求的相关处理,即第一次握手:本文主要分析第一次握手中被动打开端的处理流程,主动打开端的处理请查阅本 ...
- jmeter也能做Webservice接口测试
百度到天气预报接口:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 新增RPC接口线程 调取的参数及调取天气结果的显示 ...
- 开源运维自动化平台-opendevops
开源运维自动化平台-opendevops 简介 官网 | Github| 在线体验 CODO是一款为用户提供企业多混合云.自动化运维.完全开源的云管理平台. CODO前端基于Vue iview开发. ...
- Linux安全工具之fail2ban防爆力破解
一:简单介绍 fail2ban是一款实用软件,可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作 在企业中,有些很多人会开放root登录,这样就有机会给黑客造成暴力破解的机会 ...
- rocketmq 以广播方式实现消费者消费消息
package com.bfxy.rocketmq.model; import java.util.List; import org.apache.rocketmq.client.consumer.D ...
- 5.Hiveguigun滚(ノ`Д)ノ竟然竞争谨慎谨慎谨慎哈喇子罢工八公
1.Hive简介 2.Hive部署与安装 3.Hive的使用 4.Hive JDBC编程