hust 1010 The Minimum Length(KMP求最小循环节)
2015-10-31 22:25
447 查看
The Minimum Length
Time Limit:1000MS Memory Limit:131072KB 64bit
IO Format:%lld & %llu
Description
There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I got a new string: AAAAAA...... Now I cut it from two different position and get a new string B. Then, give you the string B, can you tell me the length of the
shortest possible string A. For example, A="abcdefg". I got abcd efgabcdefgabcdefgabcdefg.... Then I cut the red part: efgabcdefgabcde as string B. From B, you should find out the shortest A.
Input
Multiply Test Cases. For each line there is a string B which contains only lowercase and uppercase charactors. The length of B is no more than 1,000,000.
Output
For each line, output an integer, as described above.
Sample Input
Sample Output
最小循环节:/article/4990563.html
Time Limit:1000MS Memory Limit:131072KB 64bit
IO Format:%lld & %llu
Description
There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I got a new string: AAAAAA...... Now I cut it from two different position and get a new string B. Then, give you the string B, can you tell me the length of the
shortest possible string A. For example, A="abcdefg". I got abcd efgabcdefgabcdefgabcdefg.... Then I cut the red part: efgabcdefgabcde as string B. From B, you should find out the shortest A.
Input
Multiply Test Cases. For each line there is a string B which contains only lowercase and uppercase charactors. The length of B is no more than 1,000,000.
Output
For each line, output an integer, as described above.
Sample Input
bcabcab efgabcdefgabcde
Sample Output
3 7
最小循环节:/article/4990563.html
#include <stdio.h> #include <cstring> #define N 1000005 char str ; int next ; void getNext(int len) { int i=0,j=-1; next[0]=-1; while(i<len) { if(j==-1||str[i]==str[j]) { i++;j++; next[i]=j; } else j=next[j]; } } int main() { while(~scanf("%s",str)) { int len=strlen(str); getNext(len); printf("%d\n",len-next[len]); } return 0; }
相关文章推荐
- 彼得原理(The Peter Principle)
- [HDOJ]BestCoder Round #61
- PHP(Hypertext Preprocessor)
- C#集合u
- 解决Hadoop 2.7.1无法加载本地库问题
- AIC准则选三个变量的r语言代码
- openStack 初步学习
- HDU 5525 Product
- hdu 1045 Fire Net
- Local Reference and Global Reference
- hdoj--1028--Ignatius and the Princess III(母函数)
- 单链表实现(1)
- 我决定采取策略
- HOJ-1005
- 《软件需求十步走》阅读笔记三
- hdoj--1028--Ignatius and the Princess III(母函数)
- Android 内存优化(1)
- grunt-watch
- 读大型网站架构设计
- 十大思想实验(思维风暴)