POJ2774 & 后缀数组模板题】的更多相关文章

题意: 求两个字符串的LCP SOL: 模板题.连一起搞一搞就好了...主要是记录一下做(sha)题(bi)过程心(cao)得(dan)体(xin)会(qing) 后缀数组概念...还算是简单的,过程也非常清晰...就是老人家...马丹代码那么写意真的是...每一句代码的意思大概都知道但是不能很准确的描述...自己实现又漏洞百出...所以虽然避免了抄模板...但还是相当于一个默写的过程... 然后这个题目...非常显然嘛不是...然后就打了...然后开始调...TLE...TLE...TLE..…
BZOJ 1031 [JSOI2007]字符加密Cipher | 后缀数组模板题 将字符串复制一遍接在原串后面,然后后缀排序即可. #include <cmath> #include <cstdio> #include <cstring> #include <algorithm> #define space putchar(' ') #define enter putchar('\n') using namespace std; typedef long l…
题意 给定字符串A.B,求其最长公共子串 后缀数组模板题,求出height数组,判断sa[i]与sa[i-1]是否分属字符串A.B,统计答案即可. #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorithm> #include <iostream> using namespace std; ; char st…
Language: Default Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 21228   Accepted: 8708 Case Time Limit: 1000MS Description The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes…
好气啊,今天没有看懂后缀树和后缀自动机 只能写个后缀数组发泄一下了orz #include <cstdio> #include <cstring> *; int wa[N], wb[N], wv[N], ws[N]; int rank[N]; int height[N]; char str[N]; int s[N], sa[N]; int cmp(int *r, int a, int b, int l) { return r[a]==r[b] && r[a+l]==…
题目链接 题意 问两个字符串的最长公共子串. 思路 加一个特殊字符然后拼接起来,求得后缀数组与\(height\)数组.扫描一遍即得答案,注意判断起始点是否分别在两个串内. Code #include <bits/stdc++.h> #define maxn 200010 using namespace std; typedef long long LL; int a[maxn], wa[maxn], wb[maxn], wv[maxn], wt[maxn], h[maxn], rk[maxn…
后缀数组,解决字符串问题的有利工具,本题代码为倍增SA算法 具体解释详见2009年国家集训队论文 #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> using namespace std; ]; ][],U[],T…
P3809 [模板]后缀排序 题目链接:https://www.luogu.org/problemnew/show/P3809 题目背景 这是一道模板题. 题目描述 读入一个长度为 nn 的由大小写英文字母或数字组成的字符串,请把这个字符串的所有非空后缀按字典序从小到大排序,然后按顺序输出后缀的第一个字符在原串中的位置.位置编号为 11 到 nn. 输入输出格式 输入格式: 一行一个长度为 nn 的仅包含大小写英文字母或数字的字符串. 输出格式: 一行,共n个整数,表示答案. 输入输出样例 输入…
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1031 [题意] [题解] 后缀数组模板题; 把整个字符串扩大一倍. 即长度乘2 然后搞出后缀数组; 然后顺序枚举i; 对于sa[i]< n的输出对应的s[sa[i]+n-1]就好了 后缀的含义是把后缀按照字典序从小到大排一下. 按照这个规则; 就能搞了; 必然是在前n个字符中就能比较出来; 所以及时后缀多了一些也没事. [完整代码] #include <bits/stdc++.h&…
http://uoj.ac/problem/35 以前做后缀数组的题直接粘模板...现在重新写一下模板 注意用来基数排序的数组一定要开到N. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 100003; int t1[N], t2[N], c[N]; void st(int *x, int *y, int *sa, int n, int…