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. Javascript中正则的 match、test、exec使用方法和区别

    总结: match 是str调用 test和exec是正则表达式调用 test只返回true或false, exec和match的结果是相同的,返回结果比较复杂

  2. shell单引号屏蔽变量方法

    [goforit ~]$ name="玖零後大叔" [goforit~]$ echo $name 玖零後大叔 [goforit ~]$ echo "$name" ...

  3. 一次AIX LVM PV重复PVID故障处理记录

    故障背景:客户需要把AIX 5.3.10上的一些VG做两台存储之间的LVM级别的Mirror,存储使用的是两台EMC DMX3,但是由于两套SAN存储之前是使用EMC的软件做存储级别的Mirror,所 ...

  4. MAC下搭建appium UI自动化环境

    参考资料: http://qa.blog.163.com/blog/static/190147002201510161119832/ http://blog.csdn.net/liuchunming0 ...

  5. ListView阻尼效果

    效果图省略.. . activity_main.xml(仅仅有一个自己定义ListView) <RelativeLayout xmlns:android="http://schemas ...

  6. oracle之ROWNUM的查询应用

    1 在ORACLE数据库中,ROWNUM是ORACLE数据库为查询结果加入的一个伪列.起始值为1.经常使用来处理查询结果的分页. 2 因为ROWNUM的特殊性,使用时候一般是分三层: 第一层:先进行查 ...

  7. acme.sh建立SAN证书 和泛域名证书

    文件来源 https://github.com/Neilpang/acme.sh/wiki/How-to-issue-a-cert domain=$domain time=`date +%Y%m%d% ...

  8. javascript 左侧菜单

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 在spring-mybatis.xml 中配置pagehelper

    maven导包:<dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</ ...

  10. Gym - 100625E Encoded Coordinates 矩阵快速幂

    题意: 一直TLE我也是醉了,,不爽! #include <iostream> #include <cstdio> #include <fstream> #incl ...