http://acm.hdu.edu.cn/showproblem.php?pid=1358

Period

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4849    Accepted Submission(s): 2353

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
 
#include<stdio.h>
#include<string.h>
#define N 1000007 char S[N];
int Next[N]; void FindNext(int Slen)
{
int i=, j=-;
Next[] = -; while(i<Slen)
{
if(j==- || S[i]==S[j])
Next[++i] = ++j;
else
j = Next[j];
}
} int main()
{
int n, iCase=; while(scanf("%d", &n), n)
{
int i; scanf("%s", S);
FindNext(n); printf("Test case #%d\n", iCase++);
for(i=; i<=n; i++)
{
if(i%(i-Next[i])== && Next[i]) ///这里是个坑,当Next[i]==0的时候虽然满足前面的条件,但是它的前缀和后缀的最大匹配度是0
printf("%d %d\n", i, i/(i-Next[i]));
} printf("\n");
}
return ;
}

(KMP 根据循环节来计算)Period -- hdu -- 1358的更多相关文章

  1. HDU 3746 Cyclic Nacklace (KMP求循环节问题)

    <题目链接> 题目大意: 给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数. [>>>kmp next函数 kmp的周期问题]  #include &l ...

  2. HDU 1358 Period(KMP+最小循环节)题解

    思路: 这里只要注意一点,就是失配值和前后缀匹配值的区别,不懂的可以看看这里,这题因为对子串也要判定,所以用前后缀匹配值,其他的按照最小循环节做 代码: #include<iostream> ...

  3. (KMP扩展 利用循环节来计算) Cyclic Nacklace -- hdu -- 3746

    http://acm.hdu.edu.cn/showproblem.php?pid=3746 Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others ...

  4. HDU 1358 Period (kmp求循环节)(经典)

    <题目链接> 题目大意: 意思是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第 ...

  5. HDU 3746 Cyclic Nacklace(KMP+最小循环节)题解

    思路: 最小循环节的解释在这里,有人证明了那么就很好计算了 之前对KMP了解不是很深啊,就很容易做错,特别是对fail的理解 注意一下这里getFail的不同含义 代码: #include<io ...

  6. HDU - 3374 String Problem (kmp求循环节+最大最小表示法)

    做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. ...

  7. KMP与循环节相关题目

    HDU 3746 Cyclic Nacklace ( KMP求最小循环节 ) len - nextval[len]即为最小循环节长度. #include <cstdio> #include ...

  8. 用KMP征服循环节问题

    以前我还是写过KMP的文章的 现在我们可以求一下循环节啊 Slot Machines Gym - 101667I #include<bits/stdc++.h> using namespa ...

  9. ( KMP 求循环节的个数)Power Strings -- poj -- 2406

    链接: http://poj.org/problem?id=2406 Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bi ...

随机推荐

  1. Vue.js路由详解

    有时候,我们在用vue的时候会有这样的需求,比如一个管理系统,点了左边的菜单栏,右边跳转到一个新的页面中,而且刷新的时候还会停留在原来打开的页面. 又或者,一个页面中几个不同的画面来回点击切换,这两种 ...

  2. 使用通用mapper 生成代码

    参考通用mapper 文档:https://github.com/abel533/Mapper/wiki/4.1.mappergenerator 使用maven 的方法: 1,修改pom.xml &l ...

  3. Js获取iframe子页面全局变量

    项目中通过iframe内嵌了一个子页面,子页面定义了一些全局变量,父页面需要获取子页面的全局变量,做了一些测试(我的环境IE10和Firefox32.0.3),得出如下结论: IE下: window. ...

  4. <a>, <input>, <button>的区分与何时使用

    像 button 的原始目的就是一个通用的按钮,点击后应该触发 JavaScript, 没有其它附带的隐含的附加效果,<a> 标签的隐含附带效果就是跳转页面到其它地方,而提交表单时应该有一 ...

  5. VB 共享软件防破解设计技术初探(二)

    VB 共享软件防破解设计技术初探(二) ×××××××××××××××××××××××××××××××××××××××××××××× 其他文章快速链接: VB 共享软件防破解设计技术初探(一)http ...

  6. x86汇编知识点汇总

    目录: 1.进制转换 2.原码.反码.补码 3.寄存器 4.存储器的段结构 5.堆栈 6.传送类指令 7.算术运算类指令(不含乘除) 8.位操作类指令 9.标志位操作指令 10.标识符.常量与变量 1 ...

  7. C语言字符串操作函数实现

    1.字符串反转 – strRev void strRev(char *str) { assert(NULL != str);   int length=strlen(str); ; while(end ...

  8. 淘宝、天猫又开源了一个动态化、高性能的UI框架

    前言 淘宝.天猫一直致力于解决 页面动态化的问题 在2017年的4月发布了v1.0解决方案:Tangram模型 及其对应的 Android库 vlayout,该解决方案在手机淘宝.天猫 Android ...

  9. winobj

    查看系统对象 windbg+pdb符号信息 查询各个系统的内核对象结构

  10. 记录pytorch的几个问题

    1.Variable里面的creator没有,网上博客上面说有,奇怪??