有哪些ui的设计网站,唐山的网站建设公司,向国旗致敬做时代新人网站,青海西宁学做网站在哪正题
链接#xff1a; http://poj.org/problem?id2406 大意
一个字符串#xff0c;求最小循环节。 解题思路
用KMP求循环节。 因为如果有循环节那么一定是l-next[l]。只需要判断一下l-next[l]是否可以被l整除就好了 代码
#includecstdio
#includecstring http://poj.org/problem?id2406 大意
一个字符串求最小循环节。 解题思路
用KMP求循环节。 因为如果有循环节那么一定是l-next[l]。只需要判断一下l-next[l]是否可以被l整除就好了 代码
#includecstdio
#includecstring
using namespace std;
char s[1000051];
int l,p[1000051];
void ycl()//KMP自我匹配
{p[0]-1;for (int i1,j-1;il;i){while (j0s[i]!s[j1]) jp[j];if (s[i]s[j1]) j;p[i]j;}
}
int main()
{while (true){scanf(%s,s);if (s[0].) break;lstrlen(s);ycl();if (l%(l-p[l-1]-1)) printf(1);else printf(%d,l/(l-p[l-1]-1));//输出printf(\n);}
}