http://poj.org/problem?id=1961

Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 18542   Accepted: 9007

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 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

Source

 
 
 next数组的应用,代码意会吧、、
 #include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int N(+);
int len,p[N];
char s[N]; inline void Get_next()
{
for(int j=,i=;i<=len;p[i++]=j)
{
for(;s[i]!=s[j+]&&j>;) j=p[j];
if(s[i]==s[j+]) j++;
}
} int main()
{
for(int i=;scanf("%d",&len)&&len;)
{
scanf("%s",s+);
memset(p,,sizeof(p));
Get_next();
printf("Test case #%d\n",++i);
for(int i=;i<=len;i++)
{
int l=i-p[i];
if(i!=l&&i%l==)
printf("%d %d\n",i,i/l);
}
printf("\n");
}
return ;
}

POJ——T 1961 Period的更多相关文章

  1. KMP POJ 1961 Period

    题目传送门 /* 题意:求一个串重复出现(>1)的位置 KMP:这简直和POJ_2406没啥区别 */ /******************************************** ...

  2. poj 1961 Period

    Period http://poj.org/problem?id=1961 Time Limit: 3000MS   Memory Limit: 30000K       Description Fo ...

  3. POJ 1961 Period( KMP )*

    Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...

  4. POJ 1961 Period(KMP)

    http://poj.org/problem?id=1961 题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数. 思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是K ...

  5. POJ 1961 Period KMP算法next数组的应用

    题目: http://poj.org/problem?id=1961 很好的题,但是不容易理解. 因为当kmp失配时,i = next[i],所以错位部分就是i - next[i],当s[0]...s ...

  6. (简单) POJ 1961 Period,扩展KMP。

    Description For each prefix of a given string S with N characters (each character has an ASCII code ...

  7. poj 1961 Period 【KMP-next前缀数组的应用】

    题目地址:http://poj.org/problem?id=1961 Sample Input 3 aaa 12 aabaabaabaab 0 Sample Output Test case #1 ...

  8. KMP——POJ-3461 Oulipo && POJ-2752 Seek the Name, Seek the Fame && POJ-2406 Power Strings && POJ—1961 Period

    首先先讲一下KMP算法作用: KMP就是来求在给出的一串字符(我们把它放在str字符数组里面)中求另外一个比str数组短的字符数组(我们叫它为ptr)在str中的出现位置或者是次数 这个出现的次数是可 ...

  9. poj 1961 Period【求前缀的长度,以及其中最小循环节的循环次数】

    Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 14653   Accepted: 6965 Descripti ...

随机推荐

  1. Windows 10 计划带来颜文字和Sandbox

    在最新的 Window 10 测试版 Build 18305 中,Windows 10 增加了对颜文字(kaomoji)的支持. Kaomoji 是由日本符号序列组成的面脸部表情的名称.虽然有些人,比 ...

  2. Spring配置方式

    Spring配置方式 第一阶段:xml配置     在spring 1.x时代,使用spring开发满眼都是xml配置的bean,随着项目的扩大, 我们需要把xml配置文件分放到不同的配置文件中,那时 ...

  3. ECNUOJ 2149 华丽的队列

    华丽的队列 Time Limit:3000MS Memory Limit:65536KBTotal Submit:531 Accepted:68 Description  每年,都有很多新同学来到我们 ...

  4. HTML学习----------DAY1 第三节

    本章通过实例向您演示最常用的 HTML 标签. 提示:不要担心本章中您还没有学过的例子,您将在下面的章节中学到它们. 提示:学习 HTML 最好的方式就是边学边做实验.我们为您准备了很好的 HTML ...

  5. 火狐不支持innerText属性,只支持innerHTML属性

    做的一个js的小程序放到火狐上用不了了,原因是innerText不是标准属性,换成innerHTML属性就好,但是可能需要把html标签给去掉

  6. 水池接雨水的经典问题I&II

    https://leetcode.com/problems/trapping-rain-water https://leetcode.com/problems/trapping-rain-water- ...

  7. 在kettle中实现数据验证和检查

    在kettle中实现数据验证和检查 在ETL项目,输入数据通常不能保证一致性.在kettle中有一些步骤能够实现数据验证或检查.验证步骤能够在一些计算的基础上验证行货字段:过滤步骤实现数据过滤:jav ...

  8. .NET进阶——ORM基础认识

    ORM对象关系映射,对象即实体,关系即关系数据库表.ORM即实现从实体对象关系数据库数据的映射. 本质上就是将数据从一种形式转换到还有一种形式.它详细又有哪些表现呢.咱们一步步学习,一步步分析. OR ...

  9. SOAPUI使用

    简介:在开发接口的时候每次验证接口是否正确都需要手动写测试DEMO来验证,使用SOAPUI可以大大减少测试时间. 目录 1.SOPUI介绍... 1 2.SOAPUI使用... 1 2.1新建SOAP ...

  10. Codeforces 344D Alternating Current 简单使用栈

    Description Mad scientist Mike has just finished constructing a new device to search for extraterres ...