当前位置:网站首页>poj1961 Period(KMP)
poj1961 Period(KMP)
2022-08-08 17:24:00 【51CTO】
C - Period
Crawling in process...
Crawling failed
Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u
Submit Status Practice POJ 1961
System Crawler (2016-05-10)
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 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
Sample Output
第二次做KMP算法了 可惜的是我见到了都不知道是要用KMP算法做 唉
上次做也没有深刻理解next数组的意义 做了这道题 让我理解到 (仅仅是我的理解,错了别喷我。。)next数组的作用就是在匹配主串的时候
遇到了不相同的字符 通过next数组快速跳过已经匹配过的字符。具体解释请看这位大牛写的
做了这道题也知道了next数组可以找循环节 唉 真的想不到
边栏推荐
- 二、pytest+selenium+allure实现web ui自动化
- 差分约束做法
- C语言中变量在内存中的保存与访问
- Qt——选择文件夹并获取路径以及文件夹下子文件
- L2-021 点赞狂魔 (25 分)
- Are Huishang Futures official and reliable?Is it safe to open an account in Huishang Futures?
- Solve the inexplicable problem of MySQL violently - restart the service!
- LeetCode_回溯_中等_491.递增子序列
- 看到这个应用上下线方式,不禁感叹:优雅,太优雅了!
- DSPE-PEG-Biotin,385437-57-0,磷脂-聚乙二醇-生物素用于生物分子的检测和纯化
猜你喜欢
随机推荐
文件操作和IO
新版松鼠as换源操作
Cholesterol-PEG-DBCO,CLS-PEG-DBCO,胆固醇-聚乙二醇-二苯基环辛炔一种环炔烃
【NodeJs篇】fs文件系统模块
通俗易懂的epoll
L2-009 抢红包 (25 分)(结构体+自定义排序)
DSPE-PEG-NH2,DSPE-PEG-amine,474922-26-4,磷脂-聚乙二醇-氨基科研试剂
[Paper Reading] RAL 2022: Receding Moving Object Segmentation in 3D LiDAR Data Using Sparse 4D Convolutions
Is it safe to open an account with CICC Wealth?How does it work?
永续合约交易所系统开发逻辑详情
H. Huge Boxes of Animal Toys
开源一夏 | 疫情期间闲来无事,我自制了一个按钮展示框特效来展示我的博客
史上最强IDEA工具使用教程,你想要的全都有!
L2-008 最长对称子串 (25 分)
L2-011 玩转二叉树 (25 分) (二叉树)
dp, dpi, px knowledge supplement
B. Stairs
L2-021 点赞狂魔 (25 分)
laravel - query builder 2
B+树与B-树的区别