题意:

n<=1000000,cas较大

思路:这是一道论文题

后缀数组已弃疗,强行需要DC3构造,懒得(不会)写

 var a,x,y,sa,rank,height,dp,wc,wd:array[..]of longint;
n,m,i,j,len,ans,st:longint;
ch:ansistring;
flag:boolean; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; function cmp(a,b,l:longint):boolean;
begin
exit((y[a]=y[b])and(y[a+l]=y[b+l]));
end; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; procedure getsa(n:longint);
var i,j,p:longint;
begin
for i:= to m do wc[i]:=;
for i:= to n- do
begin
x[i]:=a[i];
inc(wc[a[i]]);
end;
for i:= to m- do wc[i]:=wc[i-]+wc[i];
for i:=n- downto do
begin
dec(wc[x[i]]);
sa[wc[x[i]]]:=i;
end;
j:=; p:=;
while p<n do
begin
p:=;
for i:=n-j to n- do
begin
y[p]:=i; inc(p);
end;
for i:= to n- do
if sa[i]>=j then begin y[p]:=sa[i]-j; inc(p); end;
for i:= to n- do wd[i]:=x[y[i]];
for i:= to m- do wc[i]:=;
for i:= to n- do inc(wc[wd[i]]);
for i:= to m- do wc[i]:=wc[i-]+wc[i];
for i:=n- downto do
begin
dec(wc[wd[i]]);
sa[wc[wd[i]]]:=y[i];
end;
for i:= to n do swap(x[i],y[i]);
p:=; x[sa[]]:=;
for i:= to n- do
if cmp(sa[i-],sa[i],j) then x[sa[i]]:=p-
else begin x[sa[i]]:=p; inc(p); end;
j:=j*;
m:=p;
end;
end; procedure getheight(n:longint);
var i,j,k:longint;
begin
for i:= to n do rank[sa[i]]:=i;
k:=;
for i:= to n- do
begin
if k> then dec(k);
j:=sa[rank[i]-];
while a[i+k]=a[j+k] do inc(k);
height[rank[i]]:=k;
end;
end; {procedure init;
begin
fillchar(a,sizeof(a),0);
fillchar(x,sizeof(x),0);
fillchar(y,sizeof(y),0);
fillchar(sa,sizeof(sa),0);
fillchar(rank,sizeof(rank),0);
fillchar(height,sizeof(height),0);
fillchar(dp1,sizeof(dp1),0);
fillchar(dp2,sizeof(dp2),0);
end; } begin
assign(input,'data.in'); reset(input);
assign(output,'poj2406.out'); rewrite(output);
while not eof do
begin
//init;
readln(ch);
n:=length(ch);
if ch='.' then break;
for i:= to n do
begin
height[i]:=; sa[i]:=; rank[i]:=;
dp[i]:=;
end;
for i:= to n- do a[i]:=ord(ch[i+]);
a[n]:=; m:=;
getsa(n+);
getheight(n);
dp[rank[]]:=maxlongint;
for i:=rank[]+ to n do dp[i]:=min(height[i],dp[i-]);
for i:=rank[]- downto do dp[i]:=min(height[i+],dp[i+]);
ans:=;
for i:= to n div do
if n mod i= then
begin
st:=n-i;
if dp[rank[i]]=n-i then begin ans:=n div i; break; end;
end;
writeln(ans);
end;
end.

显然钦定的算法是KMP

 var a:ansistring;
next:array[..]of longint;
n,i,j:longint; begin while not eof do
begin
readln(a);
if a='.' then break;
n:=length(a);
i:=; j:=;
next[]:=;
while j<=n do
begin
if (i=)or(a[i]=a[j]) then
begin
inc(i); inc(j);
next[j]:=i;
end
else i:=next[i];
end;
if n mod (n-next[n+]+)= then
writeln(n div (n-next[n+]+))
else writeln();
for i:= to n+ do next[i]:=;
end; end.

【POJ2406】Power Strings(KMP,后缀数组)的更多相关文章

  1. POJ2406 Power Strings(KMP,后缀数组)

    这题可以用后缀数组,KMP方法做 后缀数组做法开始想不出来,看的题解,方法是枚举串长len的约数k,看lcp(suffix(0), suffix(k))的长度是否为n- k ,若为真则len / k即 ...

  2. POJ2406 Power Strings —— KMP or 后缀数组 最小循环节

    题目链接:https://vjudge.net/problem/POJ-2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Tot ...

  3. poj2406 Power Strings (kmp 求最小循环字串)

    Power Strings   Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 47748   Accepted: 19902 ...

  4. POJ - 2406 Power Strings (后缀数组DC3版)

    题意:求最小循环节循环的次数. 题解:这个题其实可以直接用kmp去求最小循环节,然后在用总长度除以循环节.但是因为在练后缀数组,所以写的后缀数组版本.用倍增法会超时!!所以改用DC3法.对后缀数组还不 ...

  5. POJ2406 Power Strings(KMP)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 56162   Accepted: 23370 Description Giv ...

  6. POJ2406 Power Strings KMP算法

    给你一个串s,如果能找到一个子串a,连接n次变成它,就把这个串称为power string,即a^n=s,求最大的n. 用KMP来想,如果存在的话,那么我每次f[i]的时候退的步数应该是一样多的  譬 ...

  7. poj2406 Power Strings(kmp)

    poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include & ...

  8. POJ2406 Power Strings 【KMP 或 后缀数组】

    电源串 时间限制: 3000MS   内存限制: 65536K 提交总数: 53037   接受: 22108 描述 给定两个字符串a和b,我们定义a * b是它们的连接.例如,如果a =" ...

  9. poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)

    http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submiss ...

  10. POJ2406Power Strings (最小循环节)(KMP||后缀数组)

    Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...

随机推荐

  1. AJPFX的内存管理小结

    管理范围:任何继承于 NSObject的对象原理:每一个对象都有引用计数器当使用alloc new 和 copy创建对象时引用计数器被设置为1给对象发送一条retain消息 ,引用计数器加1     ...

  2. CF778A(round 402 div.2 D) String Game

    题意: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. B ...

  3. var、符号运算、条件语句、三元(目)运算、自加和自减

    1.var  a=“hello world” a 这个变量是字符串了,对于里面的每一个字母来说,他是字节,里面有11个字节,(包括空格),字节总数用length表示 2.符号运算 + 字符串拼接 . ...

  4. 【学习笔记】block、inline(替换元素、不可替换元素)、inline-block的理解

    本文转载 总体概念 block和inline这两个概念是简略的说法,完整确切的说应该是 block-level elements (块级元素) 和 inline elements (内联元素).blo ...

  5. Android模板制作

    本文详细介绍模板相关的知识和如何制作Android模版及使用,便于较少不必要的重复性工作.比如我在工作中如果要创建一个新的模块,就不要需要创建MVP相关的几个类:Model.View.Presente ...

  6. ZigBee cc2530芯片学习 error记录(1)

    ZigBee cc2530芯片学习 error记录   Error[e46]: Undefined external "LcdInit" referred in main( xxx ...

  7. COGS 2098. Asm.Def的病毒

    ★☆   输入文件:asm_virus.in   输出文件:asm_virus.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] “这就是我们最新研制的,世界上第一种可持 ...

  8. Servlet 3.0 新特性详解 (转载)

    原文地址:https://www.ibm.com/developerworks/cn/java/j-lo-servlet30/ Servlet 3.0 新特性概述 Servlet 3.0 作为 Jav ...

  9. swfit:运算符重载 Operator Methods

    Operator Methods Classes and structures can provide their own implementations of existing operators. ...

  10. AndroidStudio连不上天天模拟器

    问题:天天模拟器经常无法被Android Studio读取出来: 解决方法:手动连接它的端口: 方法一:找到Android\SDK\platform-tools目录,在当前目录下打开命令行窗口(shi ...