kmp,根据next数组的性质如果有答案的话就是n/(n-(ne[n]+1)),否则是1
搬来打算用SA后来发现必须用DC3就没写
poj 2406 Power Strings【kmp】

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1000005;
int n,ne[N];
char s[N];
int main()
{
	while(scanf("%s",s)&&s[0]!='.')
	{
		n=strlen(s);
		ne[0]=-1;
		for(int i=1,j=-1;i<n;i++)
		{
			while(j!=-1&&s[i]!=s[j+1])
				j=ne[j];
			if(s[i]==s[j+1])
				j++;
			ne[i]=j;
		}
		ne[n]=ne[n-1]+1;
		if(n%(n-ne[n])==0)
			printf("%d\n",n/(n-ne[n]));
		else
			puts("1");
	}
	return 0;
}

相关文章:

  • 2021-08-26
  • 2021-08-12
  • 2021-06-08
  • 2022-01-18
  • 2021-08-13
  • 2022-01-23
  • 2021-09-24
猜你喜欢
  • 2021-06-10
  • 2021-07-11
  • 2021-08-07
  • 2022-02-05
  • 2022-01-13
  • 2021-11-13
相关资源
相似解决方案