E - Period
InputThe input file consists of several test cases. Each test case consists of two lines. The first one contains N (2 <= N <= 1 000 000) �C 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.
OutputFor 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 结论:j%(j-Nex[t])==0 说明该前缀是一个周期为j/(j-Next[j])的周期子序列
证明: j - Next[j] 是子串在失配时候的右移长度,说明在j位置失配的时候子串转移到next[j]处继续匹配,说明j之前的部分和next[j]之前的部分是相同的,也就是说j-Next[j]
是一个周期
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
#define MAXN 1000001
typedef long long LL;
/*
*/
char s[MAXN];
int Next[MAXN];
void kmp_pre(int m)
{
int j,k;
j = ;
k = -;
Next[] = -;
while(j<m)
{
if(k==-||s[j]==s[k])
Next[++j] = ++k;
else
k = Next[k];
}
}
int main()
{
int m;
int cas=;
while(scanf("%d",&m),m)
{
scanf("%s",s);
kmp_pre(m);
printf("Test case #%d\n",cas++);
for(int i=;i<=m;i++)
if((i)%(i-Next[i])==&&i/(i-Next[i])>)
printf("%d %d\n",i,(i)/(i-Next[i]));
cout<<endl;
}
}
E - Period的更多相关文章
- TCP Provider The semaphore timeout period has expired
我们一数据库服务器上有个作业最近几天偶尔会遇到下面错误(敏感信息已做处理),主要是报"TCP Provider: The semaphore timeout period has expir ...
- SSRS 2008 R2 错误:Timeout expired. The timeout period
今天遇到了Reporting Services(SQL SERVER 2008 R2)的报表执行异常情况,报表加载数据很长时间都没有响应,最后报"An error occurred with ...
- Clock Skew , Clock Uncertainty和 Period
本文将介绍FPGA中和时钟有关的相关概念,阅读本文前需要对时序收敛的基本概念和建立.保持关系有一定了解,这些内容可以在时序收敛:基本概念,建立时间和保持时间(setup time 和 hold tim ...
- HDU 5908 Abelian Period(暴力+想法题)
传送门 Description Let S be a number string, and occ(S,x) means the times that number x occurs in S. i. ...
- Match:Period(POJ 1961)
Period 题目大意:给定一个字符串,要你找到前缀重复了多少次 思路,就是kmp的next数组的简单应用,不要修正next的距离就好了,直接就可以跳转了 PS:喝了点酒用递归实现除法和取余了...结 ...
- cargo failed to finish deploying within the timeout period [120000]
cargo插件,报错:failed to finish deploying within the timeout period [120000] 解决方法:配置timeout为0 <plugin ...
- Date get period
/** * get period for last year * @param time * @return */ public static DatePeriodDTO getLastYear(lo ...
- Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者 如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" ...
- POJ 1961 Period( KMP )*
Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...
- [LA3026]Period
[LA3026]Period 试题描述 For each prefix of a given string S with N characters (each character has an ASC ...
随机推荐
- 删除".SVN"文件夹方法(转载)
转自:http://www.cnblogs.com/lr-ting/archive/2012/09/03/2666271.html 一.在linux下 删除这些目录是很简单的,命令如下 find . ...
- PCB 规则引擎之编辑器(语法着色,错误提示,代码格式化)
对于一个规则引擎中的脚本代码编辑器是非常关键的,因为UI控件直接使用对象是规则维护者,关系到用户体验,在选用脚本编辑器的功能时除了满足代码的编辑的基本编辑要求外,功能还需要包含;语法着色,错误提示,代 ...
- oracleXE简易版---使用基础
1.开启服务 2.更改端口号 a) EX修改HTTP服务端口,避免和TOMCAT端口冲突 Oracel默认会启动HTTP服务,占有端口8080,但一般8080时TOMCAT的配置端口 可以修改TO ...
- 路一直都在——That's just life
分享一首很喜欢的歌,有时候歌词写得就是经历,就是人生... 穿过人潮汹涌灯火栏栅 没有想过回头 一段又一段走不完的旅程 什么时候能走完 我的梦代表什么 又是什么让我们不安 That's just li ...
- bzoj1433[ZJOI2009]假期的宿舍(匈牙利)
1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2544 Solved: 1074 [Submit][St ...
- flask web 表单验证 WTForms
简介 WTForms 是一个flask集成框架,或者说是库,用于处理浏览器表单提交的数据,它在flask-WTF的基础上扩展并添加了一些随手可得的精巧帮助函数,这些函数将会是在flask里使用表单更加 ...
- linux命令大杂烩之网络管理
在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具. 作为一款强力 ...
- OFDM同步算法之Schmidl算法
Schmidl算法代码 算法原理 训练序列结构 T=[A A],其中A表示复伪随机序列PN,进行N/2点ifft变换得到的符号序列 \[M(d)=\frac{\left | P(d) \right | ...
- ubuntu 安装redis以及phpredis
一.安装redis 1. 去百度搜索 redis,然后去靠谱的地方下载最新的redisxxx.tar.gz 2. 解压后,sudo make 3. sudo make install 4. //安装完 ...
- js中添加node.js语法支持
File——>settings