poj 2406 kmp算法巩固之next数组的再理解
来源:互联网 发布:java调取webservice 编辑:程序博客网 时间:2024/06/05 10:32
http://poj.org/problem?id=2406
Description
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).
Input
Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
Output
For each s you should print the largest n such that s = a^n for some string a.
Sample Input
abcdaaaaababab.
Sample Output
143
Hint
This problem has huge input, use scanf instead of cin to avoid time limit exceed.
我学习的人家的,感觉还好,似乎很容易懂#include <stdio.h>#include <string.h>#include <iostream>const int N=1000005;int next[N],len;char a[N];void get_next(){ int i=0,j=-1; next[0]=-1; while(i<len) { if(j==-1||a[i]==a[j]) next[++i]=++j; else j=next[j]; }}int main(){ while(~scanf("%s",a)) { if(a[0]=='.') break; len=strlen(a); get_next(); if(len%(len-next[len])!=0) printf("1\n"); else printf("%d\n",len/(len-next[len])); } return 0;}
0 0
- poj 2406 kmp算法巩固之next数组的再理解
- POJ 2406 KMP算法next数组理解
- poj 1961 kmp算法之next数组的意义应用
- KMP算法next数组的理解
- KMP算法对next数组的理解
- POJ 3461 Oulipo 深刻理解KMP算法next数组含义
- poj 1961kmp next的再理解
- POJ 2406 KMP next数组的应用
- kmp算法之next数组
- KMP--next数组的理解
- POJ 2752 kmp next数组理解
- 字符串匹配的KMP算法---理解next数组的意义
- HDU 3336 KMP算法中对next数组的理解
- 对kmp算法next数组的一些简单理解
- KMP算法求next数组的一些理解
- POJ 2752 KMP算法中next数组的应用
- Seek the Name, Seek the Fame(KMP算法之next数组的深入理解实例)
- KMP算法的next数组
- 【wikioi1155】金明的预算方案(noip2006, 9018p1210, tyvj1057)
- 64位PC下py2.7安装setuptools的问题
- 百度面试题
- Android Launcher全面剖析
- codeforces Round #237(div2) B解题报告
- poj 2406 kmp算法巩固之next数组的再理解
- opencv 中的cvMat详解
- 参考
- 记录我的第一场笔试和电话面试
- Android 常用URI
- 涨水问题 (简单几何+二分查找)
- 浏览器探究——多窗口
- C++虚表
- 【poj2001】Shortest Prefixes