hdu1358Period
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath> using namespace std; char s[];
int pn[];
int nextt[]; int main()
{
int l,z = ,i,j,k;
while(scanf("%d",&l)!=EOF,l)
{
printf("Test case #%d\n",++z);
scanf("%s",s+);
nextt[] = ;
pn[] = ;
for(i = ;i<=l;i++)
{
int t = nextt[i-];
while(t&&s[i]!=s[t+]) t = nextt[t];
if(s[i] == s[t+]) t++;
nextt[i] = t;
if(t == ) pn[i] = ;
else if(i-t == t/pn[t]) pn[i] = pn[t]+,printf("%d %d\n",i,pn[i]);
else pn[i] = ;
}
puts("");
}
}
注:hdu用next这个变量名会编译错误
hdu1358Period的更多相关文章
- Hdu-1358Period(KMP算法之next数组的应用)
题解:对于串pattern来说,如果0~i-1这个位置中循环,那么i%(i-next[i])==0 ,循环次数为 i/(i-next[i]),循环长度为 i-next[i] 例如对于串ababab来说 ...
- HDU-1358-Period(KMP, 循环节)
链接: https://vjudge.net/problem/HDU-1358#author=0 题意: For each prefix of a given string S with N char ...
- HDU--1358--KMP算法失配函数getfail()的理解--Period
/* Name: hdu--1358--Period Author: 日天大帝 Date: 20/04/17 10:24 Description: 长度/向后移动的位数 = 出现的次数 kmp其实匹配 ...
随机推荐
- FFmpeg详解
认识FFMPEG FFMPEG堪称自由软件中最完备的一套多媒体支持库,它几乎实现了所有当下常见的数据封装格式.多媒体传输协议以及音视频编解码器.因此,对于从事多媒体技术开发的工程师来说,深入研究FFM ...
- 关于.netFramework概述
这几天学了不少东西,想来还是应该总结一下,一来自己回顾一下,二来也怕自己忘记,在文章中,有很多东西就是借鉴别人的blog,笔者在这里对他们的无私奉献表示感谢.笔者的语言组织能力有限,如果在文章中出现什 ...
- sql server数据库主键自增一插入特定值
ID identity(1,1) SET IDENTITY_INSERT TableName ON INSERT TableName(ID) VALUES(110) SET IDENTITY_INSE ...
- IOS创建单例的两种方法
1.0 苹果官方写法: static AccountManager *DefaultManager = nil; + (AccountManager *)defaultManager { if ( ...
- [Tree]Count Complete Tree Nodes
Total Accepted: 22338 Total Submissions: 97234 Difficulty: Medium Given a complete binary tree, coun ...
- Linux命令记录。
引用:http://www.cnblogs.com/xiaoluo501395377/archive/2013/03/31/2992500.html 首先,需要确定的是知道的是:对于Linux系统来说 ...
- commands - `for`
internal variable of separator: IFS
- 【搜索引擎Jediael开发笔记1】搜索引擎初步介绍及网络爬虫
详细可参考 (1)书箱:<这就是搜索引擎><自己动手写网络爬虫><解密搜索引擎打桩实践> (2)[搜索引擎基础知识1]搜索引擎的技术架构 (3)[搜索引擎基础知识2 ...
- 优酷播放器demo
<!DOCTYPE html> <html lang="en-US"> <head> <meta http-equiv="Con ...
- XML新手入门 创建构造良好的XML(2)
本文描述了构建良好的XML需要遵循的规则.作者详细介绍了构建XML需要考虑的元素,如何命名约定.正确的标记嵌套.属性规则.声明和实体,以及DTD和schema的验证,十分便于新手开始学习了解XML. ...