博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(KMP 根据循环节来计算)Period -- hdu -- 1358
阅读量:7255 次
发布时间:2019-06-29

本文共 1501 字,大约阅读时间需要 5 分钟。

 

 

Period

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 4849    Accepted Submission(s): 2353

Problem Description
For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know the largest K > 1 (if there is one) such that the prefix of S with length i can be written as A
K , that is A concatenated K times, for some string A. Of course, we also want to know the period K.
 

 

Input
The input file consists of several test cases. Each test case consists of two lines. The first one contains N (2 <= N <= 1 000 000) – the size of the string S. The second line contains the string S. The input file ends with a line, having the number zero on it.
 

 

Output
For each test case, output “Test case #” and the consecutive test case number on a single line; then, for each prefix with length i that has a period K > 1, output the prefix size i and the period K separated by a single space; the prefix sizes must be in increasing order. Print a blank line after each test case.
 

 

Sample Input
3
aaa
12
aabaabaabaab
0
 

 

Sample Output
Test case #1
2 2
3 3
Test case #2
2 2
6 2
9 3
12 4
 
#include
#include
#define N 1000007char S[N];int Next[N];void FindNext(int Slen){ int i=0, j=-1; Next[0] = -1; while(i

 

转载于:https://www.cnblogs.com/YY56/p/4834522.html

你可能感兴趣的文章
Mac OS X 在Finder新建文本文件
查看>>
软件测试 -- 元素定位
查看>>
iOS 改变UILabel部分颜色
查看>>
python3下载图片
查看>>
牛B的调试工具:OzCode
查看>>
spider RPC入门指南
查看>>
Nginx 多站点配置
查看>>
批处理删除文件夹下所有文件和文件夹
查看>>
C# WinForm下,隐藏主窗体的方法
查看>>
机器学习-损失函数 (转)
查看>>
WEB项目 后台接收前端数组
查看>>
信号量与条件变量的区别
查看>>
关于plsql连接oracle数据库session失效时间设置
查看>>
三阶魔方花样玩法,公式汇总
查看>>
Python os
查看>>
Ubuntu使用ssh公钥实现免密码登录
查看>>
记一次720度托马斯回旋过狗!
查看>>
Atitit 图像处理的心得与疑惑 attilax总结
查看>>
mysql 关于日期时间的字段类型
查看>>
基于libvlc和wxWidgets的简单播放器代码阅读
查看>>