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. ResNet笔记

    参考: Deep Learning-TensorFlow (14) CNN卷积神经网络_深度残差网络 ResNet 先前的研究已经证明,拥有至少一个隐层的神经网络是一个通用的近似器,只要提高网络的深度 ...

  2. MIT挑战(如何在12个月内自学完成MIT计算机科学的33门课程|内附MIT公开课程资源和学习顺序

    译者注:本文译自Scott H. Young的博客,Scott拥有超强的学习能力,曾在12个月内自学完成麻省理工学院计算机科学的33门课程.本文就是他个人对于这次MIT挑战的介绍和总结. 版权声明:本 ...

  3. nodeJS + webStrome

    一.配置开发环境: 1.先安装node (1).访问http://nodejs.org打开安装包,正常安装,点击next即可. 为了测试是否安装成功,打开命令提示符,输入node,则进入node.js ...

  4. iOS- 如何使用Alcatraz来高效的管理Xcode-Plugin(Xcode插件)

    1.前言 相信各位iOS攻城师用的Xocde的快捷插件也不少,今天向大家分享一款能高效快捷的管理Xcode-Plugin的软件<Alcatraz>,自己亲自体验后,爱不释手.   (这里用 ...

  5. 深入理解JAVA集合系列三:HashMap的死循环解读

    由于在公司项目中偶尔会遇到HashMap死循环造成CPU100%,重启后问题消失,隔一段时间又会反复出现.今天在这里来仔细剖析下多线程情况下HashMap所带来的问题: 1.多线程put操作后,get ...

  6. sql server数据库中raiserror函数的用法

    server数据库中raiserror的作用就和asp.NET中的throw new Exception一样,用于抛出一个异常或错误.这个错误可以被程序捕捉到. raiserror的常用格式如下:ra ...

  7. 关于对i++,++i的理解

    i++,代表 先赋值,在加:++i,代表先自加再赋值:后台console例子中可以看到第一个例子:var a= i++;  i是等于1的:先赋值,所以打印出a =1的:而i++后为2:所以打印出a = ...

  8. Gitlab的安装与配置

    gitlab的安装 参考治疗:https://www.gitlab.com.cn/installation/#centos-7 http://www.21yunwei.com/archives/435 ...

  9. gitlab 本地建库配置 config

    先下git(?)https://download.tortoisegit.org/tgit/2.6.0.0/ 小乌龟下载 http://gitlab.didu86.com:9090/wxcode/fa ...

  10. Python Matplotlib绘图库 安装

    一般我们在做科学计算的时候,首先会想到的是matlab,但是呢,一想到matlab安装包那么大,我就有点不想说什么了. Matplotlib 是python最著名的绘图库,它提供了一整套和matlab ...