本文整理汇总了C++中SuffixArray::init方法的典型用法代码示例。如果您正苦于以下问题:C++ SuffixArray::init方法的具体用法?C++ SuffixArray::init怎么用?C++ SuffixArray::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SuffixArray
的用法示例。
在下文中一共展示了SuffixArray::init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
int runs;
scanf("%d", &runs);
for (int run = 1; run <= runs; ++run) {
scanf("%s", str);
int ls = strlen(str);
for (int i = 0; i < ls; ++i) num[i] = str[i];
num[ls] = 1;
for (int i = 0; i < ls; ++i) num[ls + 1 + i] = str[ls - i - 1];
num[ls+ls+1] = 0;
sa.init(num, ls + ls + 1, 128);
sa.init_rmq();
memset(vis, 0, sizeof(vis));
int ans = 0, cnt = 0;
for (int i = 1; i <= ls+ls; ++i) {
cnt = min(cnt, sa.height[i]);
if (!vis[sa[i]] && vis[ls+ls+1-sa[i]+1]) {
int t = sa.lcp(sa[i], ls+ls+1-sa[i]+1);
if (t <= cnt) continue;
ans += t - cnt;
if (cnt < t) ans = t;
} else vis[sa[i]] = 1;
}
printf("%d\n", ans);
}
return 0;
}
示例2: main
int main() {
int n, m, l, r;
set<pair<int, int> > st;
scanf("%d%d", &n, &m);
scanf("%s", buf);
sa.init(n, buf);
rmq.init(n, sa.height);
l = 0;
r = 1;
for (int i = 0; i < m; ++i) {
scanf("%s", op);
int& t = op[0] == 'L' ? l : r;
t += op[1] == '+' ? 1 : -1;
int k = sa.rank[l];
int lo = 0, hi = k;
while (lo < hi) {
int mi = (lo + hi) / 2;
if (rmq.value(mi + 1, k + 1) >= r - l) {
hi = mi;
} else {
lo = mi + 1;
}
}
st.insert(make_pair(hi, r - l));
}
printf("%d\n", (int)st.size());
return 0;
}
示例3: init_suffix_array
static void init_suffix_array( const String& s, SuffixArray& sa ) {
sa.init(s);
sa.build();
sa.buildHeight();
}