cf 762C. Two strings
因为要删去1个串(读错题),所以就直接二分搞就好了。
需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了。
#include<bits/stdc++.h>
#define LL long long
#define N 100005
#define lowbit(x) x&(-x)
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 a[N], b[N];
int fl[N], fr[N];
int la, lb, i, j, mid, l, r, a1, a2;
int main()
{
scanf("%s%s",a+,b+);
la=strlen(a+); lb=strlen(b+);
for (i=,fl[]=j=; b[i]; i++)
{
for (j++; j<=la && a[j]!=b[i]; j++);
fl[i]=j;
}
for (i=lb, fr[lb+]=j=la+; b[i]; i--)
{
for (j--; j> && a[j]!=b[i]; j--);
fr[i]=j;
}
for (l=,r=lb; l<=r;)
{
mid=(l+r)>>;
for (i=; i+mid<=lb; i++)
if (fl[i]<fr[i+mid+]) break;
if (i+mid<=lb) a1=i,a2=mid+i+,r=mid-;
else l=mid+;
}
for (int i=; i<=a1; i++) putchar(b[i]);
for (int i=a2; i<=lb; i++) putchar(b[i]);
if (a2-a1>lb) putchar('-');
return ;
}
cf 762C. 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, ...
- Codeforces 762C Two strings 字符串
Cpdeforces 762C 题目大意: 给定两个字符串a,b\((len \leq 10^5)\),让你去b中的一个连续的字段,使剩余的b串中的拼接起来的两个串是a穿的子序列.最大化这个字串的长度 ...
- CF 149E Martian Strings 后缀自动机
这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...
- CF 452E. Three strings(后缀数组+并查集)
传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次, ...
- cf 223B.Two Strings
神奇(%%题解) 题意:判断B串作为A串的子序列,不是不可以把A全部覆盖掉. 这样的话就是判断是不是A[i]最右匹配B的点和最左匹配B的点相交(重合)就好.(不重合的话B自然会空出中间一段,那么肯定不 ...
- 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树,给定的两个字符串就 ...
随机推荐
- 「国家集训队」小Z的袜子
「国家集训队」小Z的袜子 传送门 莫队板子题. 注意计算答案的时候,由于分子分母都要除以2,所以可以直接约掉,这样在开桶算的时候也方便一些. 参考代码: #include <algorithm& ...
- Xcode 9.0 报错,Safe Area Layout Guide Before IOS 9.0
解决方案就是: 第一步 第二步 第三步 重新编译.
- 2019 徐州网络赛 G Colorful String 回文树
题目链接:https://nanti.jisuanke.com/t/41389 The value of a string sss is equal to the number of differen ...
- 标准模板库中的优先队列(priority_queue)
//C++数据结构与算法(第4版) Adam Drozdek 著 徐丹 吴伟敏<<清华大学出版社>> #include<queue> priority_queu ...
- CNN算法详细分析
test_example_CNN.m train_x = double(reshape(train_x',28,28,60000))/255; test_x = double(reshape(test ...
- easyui 加载本地json 文件的方法
easyui 加载本地json 文件的方法 2017年12月15日 17:18:07 vivian_hnd 阅读数 2155 https://blog.csdn.net/vivian_wang07/a ...
- 【Python基础知识】【语法】【入门】
一.Python概述 Python是一门面向对象的编程语言,拥有强大丰富的库,没有操作系统的限制,是一种优美.清晰的编程语言. 二.Python基础语法 1.Python标识符 标识符就是程序中定义的 ...
- coding 321
三大原理(计算机原理.操作系统原理.编译原理)两个协议(TCP与HTTP协议)一种结构(数据结构)
- 自定义sort排序
java的sort自定义: 1.排序对象必须是封装类而不能是基本数据类型: 2.调用Arrays.sort(array, left, right, cmp)进行排序,array为数组,left.rig ...
- 小程序view标签靠右方法
第一种:不浮动靠右 text-align:right; 第二种:浮动靠右 float:right;