POJ 2774 后缀数组 || 二分+哈希】的更多相关文章

Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 35607   Accepted: 14275 Case Time Limit: 1000MS Description The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days…
题目链接:http://poj.org/problem?id=2774 题意:给定两个只含小写字母的字符串,求字符串的最长公共子串长度. 思路:根据<<后缀数组——处理字符串的有力工具>>的思路,字符串的任何一个子串都是这个字符串的某个后缀的前缀 .求 A和 B的最长公共子串等价于求 A的后缀和 B的后缀的最长公共前缀的最大值. 如果枚举 A 和 B的所有的后缀,那么这样做显然效率低下.由于要计算 A的后缀和 B的后缀的最长公共前缀, 所以先将第二个字符串写在第一个字符串后面, 中…
题意: 给出一个字符串,至多将其划分为n部分,每一部分取出字典序最大的子串ci,最小化 最大的ci 先看一个简化版的问题: 给一个串s,再给一个s的子串t,问能否通过将串划分为k个部分,使t成为划分后的s的字典序最大子串   对于这个问题,从串s的最后面开始,一个字符一个字符的向前推 如果当前[l,r]字典序比t大,那么[l+1,r]就要单独成为一段 比较子串字典序大小用二分+哈希 因为我们是一个字符一个字符的向前推的,所以一定是新的l使当前[l,r]字典序比t大 所以如果此时l==r,那么这个…
思考:其实很easy.就在两个串在一起.通过一个特殊字符,中间分隔,然后找到后缀数组的最长的公共前缀.然后在两个不同的串,最长是最长的公共子串. 注意的是:用第一个字符串来推断是不是在同一个字符中,刚開始用了第二个字符的长度来推断WA了2发才发现. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<…
这道题和UVa 12206一样,求至少重复出现k次的最长字串. 首先还是二分最长字串的长度len,然后以len为边界对height数组分段,如果有一段包含超过k个后缀则符合要求. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; + ; int s[maxn]; int sa[maxn], height[maxn], rank[maxn]; int t[m…
看来对height数组进行分段确实是个比较常用的技巧. 题意: 一个主题是可以变调的,也就是如果这个主题所有数字加上或者减少相同的数值,可以看做是相同的主题. 一个主题在原串中至少要出现两次,而且一定要有不相交的两次. 因为说了可以变调,所以我们处理每相邻两项的差值,这样就得到n-1个数字.然后找最大的不相交重复的连续子序列即可. 找这样的子序列还是要二分子序列的长度k,然后根据k对height进行分段,如果某一段的最大的sa值与最小的sa值相差超过k的话便符合要求. 然后强调一下几个容易出错的…
Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 31904   Accepted: 12876 Case Time Limit: 1000MS Description The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days…
思路: 论文题- 二分+对后缀分组 这块一开始不用基数排序 会更快的(其实区别不大) //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 20050 int n,k,s[N],cntA[N],cntB[N],A[N],B[N],rk[N],sa[N],tsa[N],ht[N]; struct Node{int pos…
The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days: his mother is getting ill. Being worried about spending so much on railway tickets (Byterland is such a big country, and he has to spend 1…
用一个特殊字符将两个字符串连接起来,然后找最大的height,而且要求这两个相邻的后缀的第一个字符不能在同一个字符串中. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; char s[maxn]; int n; int sa[maxn], rank[maxn], height[maxn]; int t[maxn], t2[maxn], c[maxn];…