input

n 2<=n<=1000000

长度为n的字符串,只含小写字母

output

Test case #cas

长度为i时的最小循环串 循环次数(>1)

若没有则不输出

做法:若next数组是连续的整数且next[i]+1是错位部分长度的倍数,则必有循环出现,且循环次数为(i+1)/错位部分长度

 #include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
#define MAX 100000
#define LL long long
int cas=,T,n,f[MAX*+];
char s[MAX*+];
void getFail(char*s,int*f)
{
f[]=;f[]=;
for(int i=;i<n;i++)
{
int j=f[i];
if((j+)%(i-j)==&&s[i]==s[j]) printf("%d %d\n",i+,(i+)/(i-j));
while(j&&s[i]!=s[j]) j=f[j];
f[i+]=s[i]==s[j]?j+:;
}
}
int main()
{
//freopen("/home/user/桌面/in","r",stdin);
//scanf("%d\n",&T);
while(scanf("%d",&n)==&&n)
{
scanf("%s",s);
printf("Test case #%d\n",cas++);
getFail(s,f);
printf("\n");
}
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return ;
}

UVALive - 3026 Period kmp next数组的应用的更多相关文章

  1. Uvalive - 3026 Period (kmp求字符串的最小循环节+最大重复次数)

    参考:http://www.cnblogs.com/jackge/archive/2013/01/05/2846006.html 总结一下,如果对于next数组中的 i, 符合 i % ( i - n ...

  2. 【暑假】[实用数据结构]UVAlive 3026 Period

    UVAlive 3026 Period 题目: Period   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld ...

  3. UVALive 3026(KMP算法)

    UVALive 3026     KMP中next[]数组的应用: 题意:给出一个字符串,问该字符串每个前缀首字母的位置和该前缀的周期. 思路:裸KMP直接上就是了: 设该字符串为str,str字符串 ...

  4. HDU 1358 Period(KMP next数组运用)

    Period Problem Description For each prefix of a given string S with N characters (each character has ...

  5. UVALive 3026 Period (KMP算法简介)

    kmp的代码很短,但是不太容易理解,还是先说明一下这个算法过程吧. 朴素的字符串匹配大家都懂,但是效率不高,原因在哪里? 匹配过程没有充分利用已经匹配好的模版的信息,比如说, i是文本串当前字符的下标 ...

  6. LA 3026 - Period KMP

    看题传送门:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  7. UVALIVE 3026 Period

    题意:给你一个字符串,问第i位前是否有循环节,若存在,则循环节是多少? 思路:考察失配函数f[i]的意义.只要i%(i-f[i])==0,则循环节长度为i/(i-f[i]).字符在[0,f[i]],[ ...

  8. Period UVALive - 3026(next数组)

    题意: 给出一个长度不超过1000000的字符串S, 对于该字符串的所有前缀求其周期, 如果周期K >= 2输出起始位置是第几个字符和其周期K 解析: 先求next数组 对于每一个位置如果i % ...

  9. KMP(fail数组应用) LA 3026 Period

    题目传送门 题意:(训练指南P213) 求每个前缀的最短循环节 分析:利用失配函数的性质,如果i % (i - fail[i]) == 0,那么正好错位移动一个循环节长度. #include < ...

随机推荐

  1. HDU 1040 As Easy As A+B(排序)

    As Easy As A+B Problem Description These days, I am thinking about a question, how can I get a probl ...

  2. PEiD 0.95 全插件中文绿色版

    软件名称: PEiD 0.95 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win8 / Win7 / Vista / WinXP 软件大小: 4.4MB 图片预览: 软件简介: PEiD ...

  3. Windows漏洞利用与防护(2015.8)

    Windows平台下的漏洞利用与防护 0x00 概述 在过去的二十几年,Windows作为网络安全的主战场之一,攻于防的较量从未停息过.内存破坏漏洞作为研究的重点之一,经历了很多的发展也沉淀了前辈们许 ...

  4. Cookie小解2

    Cookie最早用来标识和认证一个用户,其处理分为以下几步: 1.服务端向客户端发送Cookie 2.浏览器将Cookie保存 3.之后每次浏览器服务服务器时都会将Cookie发向服务器端 ----- ...

  5. Array对象 识记

    1.Array 创建 new Array(); new Array(size); new Array(element0, element1, ..., elementn); 2.Array 对象属性 ...

  6. vim menu乱码

    syntax enable syntax on colorscheme desert set nocompatible set filetype=c set number set wrap " ...

  7. AngularJS基础总结

    w3shools    angularjs教程  wiki   <AngularJS权威教程> Introduction AngularJS is a JavaScript framewo ...

  8. FOUNDATION_EXPORT 延伸

    一般iOS我们定义常量的方法有两种,来看下面例子 我的.h文件 1 2 FOUNDATION_EXPORT NSString * const kMyConstantString;   FOUNDATI ...

  9. dump报文转换为wrieshark报文

    我们开发中经常会出原始的报文,如下所示: 45 00 01 3d 8e 6a 00 00 80 11 ab 46 00 00 00 00 ff ff ff ff 00 44 00 43 01 29 6 ...

  10. LINQ 查询集合总的重复项

                      select new FMDS_FarmPlotNewInfo                   {                        FarmPlo ...