双指针(最大删除子串)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\)头部到最 ...
随机推荐
- TensorFlow使用记录 (九): 模型保存与恢复
模型文件 tensorflow 训练保存的模型注意包含两个部分:网络结构和参数值. .meta .meta 文件以 “protocol buffer”格式保存了整个模型的结构图,模型上定义的操作等信息 ...
- Python3学习笔记(十八):文件上传和下载
文件上传 以人人网上传头像为例,用Fiddler抓取的上传头像接口报文如下 上传头像图片代码: import requests upload_url = 'http://upload.renren.c ...
- 网络爬虫技术实现java依赖库整理输出
网络爬虫技术实现java依赖库整理输出 目录 1 简介... 2 1.1 背景介绍... 2 1.2 现有方法优缺点对比... 2 2 实现方法... 2 ...
- python递归获取目录下指定文件
获取一个目录下所有指定格式的文件是实际生产中常见需求. import os #递归获取一个目录下所有的指定格式的文件 def get_jsonfile(path,file_list): dir_lis ...
- 2018-2019-2 20165215《网络对抗技术》Exp9 :Web安全基础
目录 实验目的及内容 实验过程记录 一.Webgoat安装 二. 注入缺陷(Injection Flaws) (一)命令注入(Command Injection) (二)数字型注入(Numeric S ...
- Error:java: 错误: 不支持发行版本 5
本文链接:https://blog.csdn.net/wo541075754/article/details/70154604 在Intellij idea中新建了一个Maven项目,运行时报错如下: ...
- IDEA问题java: -source 1.6 中不支持diamond、 lambda 表达式
文章目录 一.问题:连片的java: -source 1.6 中不支持 diamond 运算符.lambda 表达式 二.解决方法: 1.在微信群里问大佬,大佬在玩游戏,回复的比较慢 2.自己查Goo ...
- tomcat manager 配置
使用网页部署新 Web 应用程序或取消现有 Web 应用程序部署,且无需重启容器. 一.开启管理 编辑 conf/tomcat-users.xml 添加如下内容,这里用户名和密码都为 tomcat & ...
- centos 6和centos7关闭防火墙的方法
centos 6 关闭命令: service iptables stop 永久关闭防火墙:chkconfig iptables off 两个命令同时运行,运行完成后查看防火墙关闭状态 ...
- VI快捷键速记
enjoy :P