博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher E - Period HDU - 1358(循环节kmp)
阅读量:4556 次
发布时间:2019-06-08

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

E - Period HDU - 1358

题目链接:

题目:

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.
InputThe 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.
OutputFor 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
3aaa12aabaabaabaab0
Sample Output
Test case #12 23 3Test case #22 26 29 312 4 题意:求出i个字母之前的字符串如果具有循环特性给出字符串的长度和其循环节的数量 思路:i-next[i]是如果具有循环节的话,那么他就是循环节的长度,当i%(i-next[i])==0的话,那么i这么长的字符串就是具有循环特性,那么i/(i-next[i])就是循环节的数量了 注意下列代码注释的部分不能那样写,因为他是优化过的kmp匹配,不能匹配到每个next[i],而一般的kmp就会每个都匹配到,从而不会造成漏解
// // Created by HJYL on 2019/8/15.//#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int maxn=1e6+10;char str[maxn];int nextt[maxn];void getnext(){ int i=0,j=-1; nextt[0]=-1; int n=strlen(str); while(i

 

 

转载于:https://www.cnblogs.com/Vampire6/p/11360537.html

你可能感兴趣的文章
topcoder 673
查看>>
Java中一些常用的类,包,接口
查看>>
下载特定区域内街景照片数据 | Download Street View Photos within Selected Region
查看>>
StarUML 破解方法
查看>>
C语言结构体
查看>>
[转]Tribon船体生产设计应用
查看>>
easy ui datagrid 让某行复选框不能选中
查看>>
第六周作业
查看>>
关于adb端口被占用的解决办法
查看>>
php 部分内置函数的使用
查看>>
字符串处理技巧
查看>>
归档及压缩命令
查看>>
Mybatis步骤
查看>>
WPF自定义控件之扩展原生控件
查看>>
《区块链100问》笔记整理——42~49问
查看>>
使用Jquery+EasyUI 进行框架项目开发案例讲解之二---用户管理源码分享
查看>>
深入理解计算机系统(1.4)---并发与并行、浅谈抽象
查看>>
函数依赖的公理化系统
查看>>
rabbitmq学习(四):利用rabbitmq实现远程rpc调用
查看>>
侯捷C++学习(二)
查看>>