Period

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2120    Accepted Submission(s): 1039

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

#include<stdio.h>
#include<string.h>
#define gs 1000010
int next[gs];
char str[gs];
void GetNext(char * str,int * next)
{
int N=strlen(str+);
next[]=;
int j=;
for(int i=;i<=N;i++)
{
while(j> && str[j+]!=str[i]) j=next[j];
if(str[j+]==str[i]) j+=;
next[i]=j;
}
}
int main()
{
int N,cas=;
while (scanf("%d",&N)!=EOF)
{
if (N==) return ;
cas++;
printf("Test case #%d\n",cas);
scanf("%s",str+);
GetNext(str,next);
for (int i=;i<=N;i++)
if (i%(i-next[i])== && i/(i-next[i])>) printf("%d %d\n",i,i/(i-next[i]));
printf("\n");
}
return ;
}

Period[HDU1358]的更多相关文章

  1. HDU1358 Period —— KMP 最小循环节

    题目链接:https://vjudge.net/problem/HDU-1358 Period Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  2. poj1961 & hdu1358 Period【KMP】

    Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 20436   Accepted: 9961 Descripti ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU1358 Period

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

  4. HDU-1358 Period 字符串问题 KMP算法 求最小循环节

    题目链接:https://cn.vjudge.net/problem/HDU-1358 题意 给一个字符串,对下标大于2的元素,问有几个最小循环节 思路 对每个元素求一下minloop,模一下就好 提 ...

  5. hdu1358 Period

    首先给个博客:http://blog.csdn.net/lttree/article/details/20732385 感觉他说的很好,尤其是引用的那个博客,清晰的说明了循环节的两个公式. http: ...

  6. HDU1358:Period

    第一次做KMP.还没有理解透. 在自己写一遍时没有让next[0]初始化为-1. 还有就是next应该是c++中的关键字,提交后编译错误. From: http://blog.csdn.net/lib ...

  7. [KMP求最小循环节][HDU1358][Period]

    题意 求所有循环次数大于1的前缀 的最大循环次数和前缀位置 解法 直接用KMP求最小循环节 当满足i%(i-next[i])&&next[i]!=0 前缀循环次数大于1 最小循环节是i ...

  8. hdu1358 Period kmp求循环节

    链接 http://acm.hdu.edu.cn/showproblem.php?pid=1358 思路 当初shenben学长暑假讲过,当初太笨了,noip前几天才理解过来.. 我也没啥好说的 代码 ...

  9. hdu1358 Period KMP

    给出一个字符串,找出所有可以作为它循环节的子串长度 利用kmp的失配数组的性质,可以直接做 #include<stdio.h> #include<string.h> ; cha ...

随机推荐

  1. 发现Select等注入语句自动跳转Code

    CODE区域: <?php $str = $_GET["keyword"]; $str00 = strtolower($str); //strtolower 变为小写函数 $ ...

  2. Linux EOF使用

    # cat << EOF > fileB   用法 例: vi ceshi.sh cat<<eof>file1 aaaa bbbb cccc dddd eof 操作 ...

  3. MySql 插入数据中文乱码

    在数据库连接URL后加上characterEncoding=UTF-8 driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/ssm ...

  4. 【云计算】Docker云平台—Docker基础

    Docker云平台系列共三讲,此为第一讲:Docker基础 参考资料: Docker官方文档:https://docs.docker.com/ Docker从入门到实践:https://yeasy.g ...

  5. 《ASP.NET MVC4 WEB编程》学习笔记------ViewBag、ViewData和TempData的使用和区别

    本文转自大卫Baby ViewBag和ViewData其实是互通的ViewBag和ViewData的区别:ViewBag 不再是字典的键值对结构,而是 dynamic 动态类型,它会在程序运行的时候动 ...

  6. schedule CCCallfunc CCCallfuncN CCCallfuncND

    schedule(schedule_selector(HelloWorld::step), 1.0f); void HelloWorld::step(float dt) { CCLog("d ...

  7. Linux shell脚本编程基础之练习篇

    shell脚本编程基础之练习篇. 1.编写一个脚本使我们在写一个脚本时自动生成”#!/bin/bash”这一行和注释信息. #!/bin/bash ] then echo "请输入一个参数& ...

  8. Java for LeetCode 160 Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  9. codeforces 478B Random Teams 解题报告

    题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...

  10. Extjs的数据读取器store和后台返回类型简单解析

    工作中用到了Extjs,从后台获取数据的时候,用到了extjs自己的Ext.data.store方法,然后封装了ExtGridReturn方法, 目的:前台用到Ext.data.store读取从后台传 ...