poj1961 Period 2012-01-11
http://162.105.81.212/JudgeOnline/problem?id=1961
_____________________________________
也是求最长重复字串。
_____________________________________
1 Program Stone; 2 var i,j,n,m:longint; 3 s:ansistring; 4 b:array[1..1000000]of longint; 5 Begin 6 assign(input,'input.in');reset(input); 7 readln(n); 8 while n<>0 do 9 begin 10 readln(s); 11 inc(m); 12 j:=0;b[1]:=0; 13 writeln('Test case #',m); 14 for i:=2 to n do 15 begin 16 while (j>0)and(s[i]<>s[j+1]) do j:=b[j]; 17 if s[i]=s[j+1] then inc(j); 18 b[i]:=j; 19 if (i mod (i-b[i])=0)and(b[i]<>0) then writeln(i,' ',i div (i-b[i])); 20 end; 21 writeln; 22 readln(n); 23 end; 24 end. 25 26
_____MildTheorem