Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
                         Total Submission(s): 9449    Accepted Submission(s): 4530
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 AK , 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

Recommend

JGShining

 

题解:

①题目要求求出每一个前缀的循环节(只循环一次不算),可以使用最小循环节长度=n-next[n]这一性质

②利用上述质,只需要判断循环节长度是否能够整除当前前缀长度并至少不含2个循环节即可输出结果

#include<stdio.h>
#define go(i,a,b) for(int i=a;i<=b;i++)
const int N=1000003;int m,f[N],j,n,T;char P[N];
int main()
{
while(scanf("%d",&m),m)
{
scanf("%s",P);printf("Test case #%d\n",++T);f[0]=f[1]=0; go(i,1,m-1){j=f[i];while(j&&P[j]!=P[i])j=f[j];f[i+1]=P[i]==P[j]?j+1:0;}
go(i,1,m-1){n=i+1-f[i+1];if((i+1)%n==0&&(i+1)/n>1)printf("%d %d\n",i+1,(i+1)/n);}
puts("");
}
return 0;
}//Paul_Guderian

我曾随迷失的航船沉没,陷入璀璨虚空的碎梦。

沉入乱欲冰封的深谷,随烂漫的星群沉没。————汪峰《再见青春》

【HDU 1358 Period】的更多相关文章

  1. hdu 1358 Period 最小循环节

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 分析:已知字符串,求其由最小循环节构成的前缀字符串. /*Period Time Limit: ...

  2. HDU 3746 - Cyclic Nacklace & HDU 1358 - Period - [KMP求最小循环节]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  3. KMP + 求最小循环节 --- HDU 1358 Period

    Period Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=1358 Mean: 给你一个字符串,让你从第二个字符开始判断当前长度 ...

  4. hdu 1358 Period

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 思路:Next数组的用法,在第i个位置上如果有i%(i-Next[i])==0的话最小循环节就是 ...

  5. HDU 1358 Period KMP

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1358 求周期问题,简单KMP—— AC代码: #include <iostream> # ...

  6. HDU 1358 Period(KMP计算周期)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目大意:给你一串字符串,判断字符串的前缀是否由某些字符串多次重复而构成. 也就是,从第1个字母 ...

  7. Hdu 1358 Period (KMP 求最小循环节)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目描述: 给出一个字符串S,输出S的前缀能表达成Ak的所有情况,每种情况输出前缀的结束位置和 ...

  8. 【HDU 4747 Mex】线段数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意:有一组序列a[i](1<=i<=N), 让你求所有的mex(l,r), mex ...

  9. 【HDU 3401 Trade】 单调队列优化dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题目大意:现在要你去炒股,给你每天的开盘价值,每股买入价值为ap,卖出价值为bp,每天最多买as ...

随机推荐

  1. 查询删除的SAP凭证

    标准报表查询:RSSCD100 函数模块:CHANGEDOCUMENT_DISPLAY, Display Change Documents 数据表查询:CDHDR, Change document h ...

  2. js字符转数字

    js字符串转数字 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后者把值转换成浮点数.只 ...

  3. 协议 - OSI七层网络协议模型

    摘自:https://www.cnblogs.com/oneplace/p/5611094.html 互联网协议 本文全文转载阮一峰老师的两篇文章,自己做了一些添加内容 参考:互联网协议入门(一) 互 ...

  4. Git的基本命令介绍

    Git的安装 进入官网下载系统所需要的版本  官网地址:https://git-scm.com/downloads 点击下载按钮官方网站一般会根据操作系统的自动下载所需要的Git版本. 下载完成后,点 ...

  5. Python全栈day 04

    Python全栈day 04 一.解释器/编译器 补充:编译型语言和解释型语言? # 编译型:代码写完后,编译器将其变成成另外一个文件,然后交给计算机执行. c c++,c# ,java # 解释型: ...

  6. mybatis <forEach>标签的使用

    MyBatis<forEach>标签的使用 你可以传递一个 List 实例或者数组作为参数对象传给 MyBatis.当你这么做的时候,MyBatis 会自动将它包装在一个 Map 中,用名 ...

  7. 笔记-ORM-sqlalchemy

    笔记-ORM-sqlalchemy 1.      ORM 1.1.    ORM框架简介 对象-关系映射(Object/Relation Mapping,简称ORM),是随着面向对象的软件开发方法发 ...

  8. python基础之模块part2

    sys: sys模块不同于os模块,这个是跟Python解释器打交道的. sys.argv:返回一个文件名开头,包含后面输入内容的 列表 import sys res = sys.argv print ...

  9. TouTiao开源项目 分析笔记12 从总体到局部 构建视频主页面

    1.构建视频主列表的整体碎片VideoTabLayout 1.1.首先创建一个VideoTabLayout package com.jasonjan.headnews.module.video; im ...

  10. Android 用Chrome浏览器打开url 自定义样式

    1.效果预览 1.1.真实效果就是从某一个APP,打开一个url,跳转到谷歌浏览器,返回之后,又回到之前的APP      1.2.说明一下条件 1.手机上必须要安装谷歌浏览器 2.手机上的默认浏览器 ...