Period
Time Limit: 3000MS   Memory Limit: 30000K
     

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

题目大意:对于字符串的每个位置i(i>1),若到i,i之前有循环节,输出i及其长度
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,t;
char s[];
int f[];
void getnext()
{
for(int i=;i<n;i++)
{
int j=f[i];
while(j&&s[i]!=s[j]) j=f[j];
f[i+]= s[i]==s[j] ? j+:;
if(i>=&&f[i+])
{
int a=i+-f[i+];
if((i+)%a==) printf("%d %d\n",i+,(i+)/a);
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
t++;
if(!n) return ;
scanf("%s",s);
memset(f,,sizeof(f));
printf("Test case #%d\n",t);
getnext();
printf("\n");
}
}

poj 1961 Period的更多相关文章

  1. KMP POJ 1961 Period

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

  2. POJ 1961 Period( KMP )*

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

  3. POJ 1961 Period(KMP)

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

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

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

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

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

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

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

  7. 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中的出现位置或者是次数 这个出现的次数是可 ...

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

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

  9. poj 1961 Period(KMP训练指南例题)

    Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 11356   Accepted: 5279 Descripti ...

随机推荐

  1. 简单实现wc.exe软件基本功能

    简单实现wc.exe软件基本功能 软件需求分析: 一.基本功能 支持 -c  统计字符数(char count) 支持 -w  统计单词数(word count) 支持 -l  统计总行数(line ...

  2. iOS开发面试题(中级)

    //想面试的童鞋们来看看自己会多少, 老鸟可以无视直接绕过...1. Object-c的类可以多重继承么?可以实现多个接口么?Category是什么?重写一个类的方式用继承好还是分类好?为什么?与Ex ...

  3. 汇编语言段和RSEG用法

    RSEG是段选择指令,要想明白它的意思就要了解段的意思.段是程序代码或数据对象的存储单位.程序代码放到代码段,数据对象放到数据段.段分两种,一是绝对段,一是再定位段.绝对段在汇编语言中指定,在用L51 ...

  4. FastReport 变量列表使用

    使用报表变量时,引用“frxVariables”单元. 变量定义在“TfrxVariable” 类: TfrxVariable = class(TCollectionItem) published p ...

  5. 深度学习:卷积神经网络(convolution neural network)

    (一)卷积神经网络 卷积神经网络最早是由Lecun在1998年提出的. 卷积神经网络通畅使用的三个基本概念为: 1.局部视觉域: 2.权值共享: 3.池化操作. 在卷积神经网络中,局部接受域表明输入图 ...

  6. using关键字

    声明导入名称空间 处理实现了IDisposeable的对象,并在作用域末尾调用Dispose方法

  7. 20135306 2.4 ELF文件格式分析

    2.4   ELF文件格式分析 20135306 黄韧 ELF全称Executable and Linkable Format,可执行连接格式,ELF格式的文件用于存储Linux程序.ELF文件(目标 ...

  8. CodeVs.1036 商务旅行 ( LCA 最近公共祖先 )

    CodeVs.1036 商务旅行 ( LCA 最近公共祖先 ) 题意分析 某首都城市的商人要经常到各城镇去做生意,他们按自己的路线去做,目的是为了更好的节约时间. 假设有N个城镇,首都编号为1,商人从 ...

  9. Go interface{}、类型断言

    在 golang 中 interface{} 可用于向函数传递任意类型的变量, 但在函数内部使用的话, 该变量的类型就是 interface{}, 也称为空接口类型 比如我们定义一个函数, 输出字符串 ...

  10. vim 折叠的用法

    http://www.cnblogs.com/fakis/archive/2011/04/14/2016213.html 1. 折叠方式 可用选项来设定折叠方式: 可在Vim 配置文件中设置 set ...