最小循环节
来源:互联网 发布:天狗街源码交易 编辑:程序博客网 时间:2024/05/21 06:37
hdu 3746(KMP) 最小循环节
分类: 数据结构 2013-04-05 20:01 157人阅读 评论(0)收藏 举报
ACM算法数据结构KMP最小循环节
http://acm.hdu.edu.cn/showproblem.php?pid=3746
/* 通过KMP中的 next 数组求最小循环节 */
题目要求:给出一个字符串,求出将字符串的全部字符最少循环2次需要添加的字符数。
- #include<stdio.h>
- #include<string.h>
- int next[100005];
- char s[100005];
- void getnext(int len)
- {
- int i,j;
- for(i=0,j=-1,next[0]=-1;i<len;){
- if(j==-1||s[i]==s[j]){
- i++;
- j++;
- next[i]=j;
- }
- else
- j=next[j];
- }
- }
- int main()
- {
- int T,length,len;
- scanf("%d",&T);
- getchar();
- while(T--){
- gets(s);
- len=strlen(s);
- getnext(len);
- length=len-next[len]; //length为最小循环节的长度
- if(len%length==0){
- if(len==length)
- printf("%d\n",length);
- else
- printf("0\n");
- }
- else{
- printf("%d\n",length-(next[len]%length));
- }
- }
- return 0;
- }
- 最小循环节
- poj2406 找最小循环节
- hdu1358(KMP+最小循环节)
- HDU3746KMP求最小循环节
- 【KMP】【HDU3746】【最小循环节】
- KMP(最小循环节)
- Period--KMP,最小循环节
- POJ2406 字符串最小循环节
- HDU3746--KMP+最小循环节
- kmp求最小循环节
- hust 1010 最小循环节
- 5.1.3(求最小循环节)
- hdu 3746(KMP) 最小循环节
- poj 1961 Period (KMP+最小循环节)
- POJ 1961 Period KMP 最小循环节
- POJ 2406 最小循环节 KMP裸题
- kmp最小循环节的求法
- [KMP求最小循环节][HDU1358][Period]
-
- JSTL(JSP标准标签库)
- vector,map各种容器类型的使用方法总结
- 剖析 Linux hypervisor
- POJ 2949 SPFA
- 最小循环节
- javascript的Foreach语法
- struct kref
- 使用 not exists, not in 须小心
- 走迷宫
- 读书笔记——数据结构(1)开篇吐槽
- 70个城市房价上涨,令人忐忑
- 关于配置到dbca输入密码时提示could not validate asmsnmp password ora-12541:no listener的问题
- 静态监听