POJ 1961 Period (KMP)
来源:互联网 发布:视频剪辑合成配音软件 编辑:程序博客网 时间:2024/06/07 12:09
解题思路:
利用next 数组的性质求解重复子串。循环节的长度为i - next[i];
#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <cmath>#include <algorithm>#include <cstdio>using namespace std;const int maxn = 1000000 + 10;char s[maxn];int n;int next[maxn];int main(){ int kcase = 1; while(scanf("%d", &n)!=EOF) { if(n == 0) break; scanf("%s", s); next[0] = 0; next[1] = 0; for(int i=1;i<n;i++) { int j = next[i]; while(j && s[i] != s[j]) j = next[j]; next[i+1] = (s[i] == s[j]) ? j + 1 : 0; } printf("Test case #%d\n", kcase++); for(int i=2;i<=n;i++) { if(next[i] > 0 && i % (i - next[i]) == 0) { printf("%d %d\n", i, i / (i - next[i])); } } printf("\n"); } return 0;}
0 0
- poj 1961:Period (KMP)
- poj 1961 Period (KMP)
- poj 1961 Period---kmp
- POJ 1961-Period:KMP
- poj 1961 Period KMP
- poj 1961 Period(KMP)
- Period - POJ 1961 KMP
- POJ 1961 Period (KMP)
- POJ Period 1961【KMP】
- POJ 1961 Period kmp
- poj 1961 Period 【KMP】
- POJ-1961(Period)(kmp())
- [poj 1961]Period[kmp]
- POJ 1961 Period (KMP)
- POJ 1961 Period(KMP)
- |poj 1961|KMP|Period
- Poj-1961-Period-【KMP】
- POJ 1961 Period (KMP)
- 实现逆波兰表达式的java计算器
- wordpress中如何自定义链接为新窗口
- poj 1088
- VMWare下扩展Linux硬盘空间
- Dubbo实例
- POJ 1961 Period (KMP)
- VMWare下扩展Linux硬盘空间
- 安卓中常用的方法总结
- 长城守卫 Beijing guards CERC 2004 LA3177 解题总结
- Apache Solr单机环境配置(包括中文分词和Java API的使用)
- 断箭:不相信自己的意志,永远也做不成将军
- 解24点的算法
- trustZone初探(一)
- Java中的两个ArrayList