POJ-1961(KMP)
来源:互联网 发布:linux目录命令 编辑:程序博客网 时间:2024/05/16 03:17
题目:http://poj.org/problem?id=1961
与poj2406几乎一样的题目,只是换了个问法:先求出next[]数组,当j-next[j]是j的因子是说明前j个字符可由前j-next[j]个字符扩展而来
#include <cstdio>#define MAX_LEN 1000000void getNext(int next[], const char* p){ next[0] = -1; int i = 0, j = -1; while(p[i]){ if(j == -1 || p[i] == p[j]){ ++i; ++j; next[i] = j; } else j = next[j]; }}int next[MAX_LEN + 2], len;char p[MAX_LEN + 1];void solve(){ getNext(next, p); for(int i = 2; i <= len; ++i){ int t = next[i]; if(t && i % (i - t) == 0) printf("%d %d\n", i, i / (i - t)); }}int main(){ int test = 0; while(scanf("%d", &len), len){ while(getchar() != '\n') ; gets(p); printf("Test case #%d\n", ++test); solve(); puts(""); } return 0;}
0 0
- POJ-1961(KMP)
- POJ 1961 (KMP)
- POJ 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 Period(KMP)
- POJ 1961Period (KMP)
- poj 1961 Period(kmp)
- (KMP) poj POJ 1961 Period
- POJ 1961 KMP(当前重复次数)
- Period (poj 1961&&hdu 1358)KMP
- POJ 题目1961 Period(KMP水)
- POJ 1961 Period(kmp循环节)
- POJ 1961 && HDU 1358 Period(kmp)
- xampp apache无法启动解决方法
- 自测题1道
- 机器学习牛人主页及相关会议,论文和期刊
- HDU 4940 无源无汇上下界最大流
- NorFlash和NandFlash有什么区别?为什么一般我们的Uboot要从NorFlash启动呢?
- POJ-1961(KMP)
- C/C++内存问题检查利器—Purify
- java数据结构-HashMap
- 第一第二第三范式的区别与联系
- POJ1182 - 食物链 - 并查集
- OpenWRT添加模块(一)Makefile和Config.in
- JUnit4学习总结
- 小苏打美白有效果吗
- VB外部调用AutoCAD