POJ刷题(2406)
来源:互联网 发布:淘宝九块九包邮在哪 编辑:程序博客网 时间:2024/05/17 07:02
程序(已经accepted):
#include<stdio.h>#include<string.h>#include<memory.h>#define N 1000010char str[N];int next[N];int get_next(char pattern[], int next[]){ int j=0,k=-1; int len=strlen(pattern); next[0]=-1; while(j<len) { if(k==-1||pattern[j]==pattern[k]) next[++j]=++k; else k=next[k]; } j=len-k;//如果最后一个位置不匹配,那么就会滚到len-k的位置,也就是最小重复字串的长度。 if(len%j==0) return len/j; else return 1;}int main(){ while(scanf("%s", str), str[0]!='.') { printf("%d\n", get_next(str, next)); } return 0;}</span><strong style="font-size:18px; color: rgb(0, 0, 153);"></strong>
运行时间:
本题还是很有价值的:
1. 考察了KMP算法的灵活应用;
2. 由于1000010*4(int型)会超过栈空间(1M),所以程序会崩溃,因此只能做全局变量。
0 0
- POJ刷题(2406)
- poj 2406(kmp)
- POJ-2406(KMP)
- POJ刷题(2013)
- POJ刷题(2499)
- KMP算法的练习题(poj 3461、poj 2752、poj 2406、poj 1961)
- POJ 2406(KMP) 证明
- POJ 水题(刷题)进阶
- KMP算法的经典例题(poj 3461、poj 2752、poj 2406、poj1961)
- POJ 2406
- POJ 2406
- poj 2406
- POJ 2406
- poj 2406
- poj 2406
- poj 2406
- poj 2406
- poj 2406
- HDU 2550百步穿杨
- 一个ASP.Net(C#)访问Cookie的封装
- 示例:将通过js获取的json字符串转换为Map、List集合(不太重要)
- excel中的筛选
- 【算法之链表(四)】在不使用额外节点存储空间的情况下,实现单链表逆序
- POJ刷题(2406)
- 设计模式---观察者模式
- 一个textview显示不同zize大小的文本
- SQL必知必会 笔记 第五章 高级过滤数据
- 11.3 TCP内核同步
- 服务端管理工具编写(三)——各控件的安排及事件
- 数组变量名能否++(int a [10];a++;)
- Ubuntu部署Apache-PartI
- error C2054:在“inline”之后应输入“(