
数据结构-后缀数组
JeraKrs
本人目前就职于百度商业研发部,有需要内推的朋友简历可发我邮箱 jerakrs@qq.com
展开
-
uva 10526 - Intellectual Property(后缀数组)
题目链接:uva 10526 - Intellectual Property题目大意:给定两个文本,问说下面一个文本中在哪些位置上抄袭了上面个一个文本的,输出n个抄袭位置(不足n个情况全部输出),按照长度优先输出,长度相同的输出位置靠前的。注意:空格,回车都算一个字符;一段字符只能是抄袭上面的一部分,比如上:NSB*SB 下:NSB 答案:NSB。解题思路:将两个文本连接在一起原创 2014-09-04 22:24:59 · 1464 阅读 · 0 评论 -
poj 1743 Musical Theme(后缀数组)
题目链接:poj 1743 Musical Theme代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 2 * 1e4 + 5;struct Suffix_Arr { int n, s[maxn]; int SA[maxn], rank[ma原创 2015-10-30 23:48:19 · 453 阅读 · 0 评论 -
hdu 4691 Front compression(后缀数组)
题目链接:hdu 4691 Front compression代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e5 + 5;typedef long long ll;struct Suffix_Arr { int n, s[maxn];原创 2015-11-09 20:35:34 · 1352 阅读 · 0 评论 -
spoj 7258 Lexicographical Substring Search(后缀数组 | 后缀自动机)
题目链接:spoj 7258 Lexicographical Substring Search代码 - 后缀数组#include <cstdio>#include <cstring>#include <stack>#include <vector>#include <algorithm>using namespace std;const int maxn = 90000 + 5;struc原创 2015-11-09 11:23:01 · 921 阅读 · 0 评论 -
poj 3415 Common Substrings(后缀数组 | 后缀自动机)
题目链接:poj 3415 Common Substrings代码-后缀数组#include <cstdio>#include <cstring>#include <stack>#include <vector>#include <algorithm>using namespace std;typedef long long ll;typedef pair<int,int> pii;c原创 2015-11-06 21:55:09 · 711 阅读 · 0 评论 -
uva 12338 - Anti-Rhyme Pairs(后缀数组+RMQ)
题目链接:uva 12338 - Anti-Rhyme Pairs题目大意:给定若干个字符串,每次询问两个字符串的最长公共前缀。解题思路:本来应该将每个字符串连接起来做后缀数组,但其实可以直接把一个字符串看成是一个字符,然后排序了就对应是SA数组,然后处理height即可。然后根据后缀数组的性质,字符串i和j的最长公共前缀长度即为rank[i]+1~rank[j]之间height的原创 2014-09-02 22:45:47 · 1105 阅读 · 0 评论 -
uva 261 - The Window Property(后缀数组)
题目链接:uva 261 - The Window Property题目大意:给定给一个字符串,枚举子串长度k(len≥k≥1),要求在任意k时,有不超过k+1个不同的子串,如果有的话则输出NO,并且输出最早发现不满足的位置。解题思路:后缀数组,处理出height数组,对于每个k,遍历height数组,碰到小于k的则分段,将整个height分成若干段,即为有多少种长度为k的不同前缀原创 2014-09-02 22:26:32 · 1006 阅读 · 0 评论 -
hdu 5008 Boring String Problem(后缀数组)
题目链接:hdu 5008 Boring String Problem题目大意:给定一个字符串,初始状态l,r为0,每次询问子串中字典序第l^r^v+1的子串区间,对于重复的输出下标小的。解题思路:后缀数组,对给定字符串做后缀数组,然后根据height数组确定每个位置做为起点的子串有多少,然后二分查找确定起点位置,但是因为子串的重复的要输出下表小的,所以确定起点后还要确定字典序最小原创 2014-09-15 18:53:41 · 1326 阅读 · 0 评论 -
hdu 5030 Rabbit's String(后缀数组)
题目链接:hdu 5030 Rabbit's String题目大意:给定k和一个字符串,要求将字符串拆分成k个子串。然后将每个子串中字典序最大的子串选出来,组成一个包含k个字符串的集合,要求这个集合中字典序最大的字符串字典序最小。解题思路:网赛的时候试图搞了一下这道题,不过水平还是有限啊,后缀数组也是初学,只会切一些水题。赛后看了一下别人的题解,把这题补上了。首先对整个字符串做原创 2014-09-26 20:44:36 · 1558 阅读 · 0 评论 -
uva 11107 - Life Forms(后缀数组)
题目链接:uva 11107 - Life Forms题目大意:给定n个字符串,求一个最长的字符串,为n/2个字符串的子串。解题思路:后缀数组,处理除后缀数组后,二分长度,每次遍历height数组,当长度不足时就分段,如果存在一段中包含n/2个起点,则为可行长度。#include #include #include #include using namespace s原创 2014-09-01 21:49:59 · 1563 阅读 · 0 评论 -
uva 12206 - Stammering Aliens(哈希)
题目链接:uva 12206 - Stammering Aliens题目大意:给出一个字符串,找出至少出现m次的最长子串。解题思路:哈希算法,将每个后缀数组建立一个哈希值,每次二分长度判断,每次判断时将哈希值排序,计数即可。#include #include #include using namespace std;typedef unsigned long lon原创 2014-09-01 21:56:23 · 1334 阅读 · 1 评论 -
poj 3693 Maximum repetition substring(后缀数组)
题目链接:poj 3693 Maximum repetition substring题目大意:求一个字符串中循环子串次数最多的子串。解题思路:对字符串构建后缀数组,然后枚举循环长度,分区间确定。对于一个长度l,每次求出i和i+l的LCP,那么以i为起点,循环子串长度为l的子串的循环次数为LCP/l+1,然后再考虑一下从i-l+1~i之间有没有存在增长的可能性。#include原创 2014-09-05 22:38:21 · 1001 阅读 · 0 评论 -
uva 10829 - L-Gap Substrings(后缀数组)
题目链接:uva 10829 - L-Gap Substrings题目大意:给定一个字符串,问有多少字符串满足UVU的形式,要求U非空,V的长度为g。解题思路;对字符串的正序和逆序构建后缀数组,然后枚举U的长度l,每次以长度l分区间,在l和l+d+g所在的两个区间上确定U的最大长度。#include #include #include #include using n原创 2014-09-05 22:31:29 · 1899 阅读 · 0 评论 -
uva 11855 - Buzzwords(后缀数组)
题目链接:uva 11855 - Buzzwords题目大意:给定一个字符串,输出重复子串长度大于1的重复次数(每种长度只算一个次数最多的),并且按照从大到小输出。解题思路:后缀数组,处理处后缀数组,然后枚举子串长度,按照长度分段即可。#include #include #include #include using namespace std;const int原创 2014-09-04 22:36:43 · 1212 阅读 · 0 评论 -
poj 2774 Long Long Message(后缀数组)
题目链接:poj 2774 Long Long Message代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 100005 * 4;struct Suffix_Arr { int n, s[maxn]; int SA[maxn], rank[原创 2015-10-30 23:49:26 · 550 阅读 · 0 评论