字符串
lllixingrui
这个作者很懒,什么都没留下…
展开
-
第 46 届 ICPC 国际大学生程序设计竞赛亚洲区域赛(沈阳) M题 题解
题目描述JB hates solving string problems. Therefore, when his friend Potato gives him a string problem to solve, he immediately gives it to you and continues playing Genshin Impact, the greatest game in the world.题意给一个字符串,输出每一字符的一个字典序最大的子串,这个子串以当前位置的字符结尾输入原创 2021-11-25 21:09:55 · 731 阅读 · 0 评论 -
求解字符串匹配问题---KMP算法
模式串匹配,给定一个需要处理的文本串和一个需要再文本串中搜索的模式串,查询再该文本串中,给出的模式串的出现有无,次数,位置等KMP的精髓在于,对于每次匹配失败后,我们都不会重新开始枚举,而是根据我们已经得知的数据,从某个特定的位置开始匹配,对于模式串的每一个,都有唯一的"特定变化位置",在这个匹配失败后的特定变化位置可以帮助我们利用已有的数据不用从头匹配,从而节约时间要求KMP我们有两个步骤1.求模式串的next数组void getnext(){int lenss=strlen(ss);int原创 2021-08-06 09:19:12 · 325 阅读 · 0 评论 -
求字符串(单词)在文本中出现与否和出现的次数---Trie树(字典树)算法
字典树模板字典树模板#include<bits/stdc++.h>#include<algorithm>using namespace std;inline int read();int next_[500000][26];//p[节点的数量][当前节点的分支数量]int f[500000];//表示是否以当前节点结尾char s[30];//词组int cnt=0;//节点的个数void insert_(int len,int n){//插入当前单词int n原创 2021-08-17 09:08:11 · 169 阅读 · 0 评论 -
KMP算法用途
为什么要使用KMP算法?比KMP算法更优的算法有很多,解决文本串匹配问题,我自己选择KMP算法和Sunday算法但是KMP算法不仅可以解决文本串匹配问题,还可以解决由KMP算法的Next数组引出来的子问题1.求最小循环子串(即最长匹配长度(Next数组里面的符号就是表示当前位置与之前匹配过的文本的最长匹配长度))例如abcabca Next数组为 0 0 0 1 2 3 42.求字符串的最短匹配长度例如abababab Next数组为 0 0 1 2 1 2 1 2 1 2(思路)3.在文本原创 2021-08-19 16:57:18 · 1119 阅读 · 0 评论 -
求字符串匹配问题---Sunday算法
Sunday算法(字符串匹配)In abcde cdeOut The index is: 2#include<bits/stdc++.h>using namespace std;void SundayMatch(const char *src, const char *patt){//传入源串(长)与模板串(短) int slen = strlen(src);//得源串长 int plen = strlen(patt);//得模板串长 int shift[256];//位移标记原创 2021-08-19 16:59:35 · 186 阅读 · 0 评论 -
求解多字符串匹配问题---AC自动机算法
思路详解来自例题1:AC自动机模板#include <queue>#include <cstdlib>#include <cmath>#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long原创 2021-09-17 20:13:06 · 73 阅读 · 0 评论