标签:
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; char s[1100000]; int pn[1100000]; int nextt[1100000]; int main() { int l,z = 0,i,j,k; while(scanf("%d",&l)!=EOF,l) { printf("Test case #%d\n",++z); scanf("%s",s+1); nextt[1] = 0; pn[1] = 1; for(i = 2;i<=l;i++) { int t = nextt[i-1]; while(t&&s[i]!=s[t+1]) t = nextt[t]; if(s[i] == s[t+1]) t++; nextt[i] = t; if(t == 0) pn[i] = 1; else if(i-t == t/pn[t]) pn[i] = pn[t]+1,printf("%d %d\n",i,pn[i]); else pn[i] = 1; } puts(""); } }
注:hdu用next这个变量名会编译错误
标签:
原文地址:http://www.cnblogs.com/wos1239/p/4397992.html