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 ...
随机推荐
- Vue 页面回退参数被当作字符串处理
当时情景是这样的,我从A页面跳到B页面时会传一个Boolean类型的参数,当B跳到C,再从C返回B的时候,控制台打印发现参数还在,可是判断怎么都不起作用,后来发现,当页面返回的时候,默认将参数变成了字 ...
- An problem about date 根据年月日计算 星期几
/W = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7(1.2月需要看作上一年的13.14月) #include<stdio.h> #include& ...
- Android开发之Intent.Action Android中Intent的各种常见作用
1 Intent.ACTION_MAIN String: android.intent.action.MAIN 标识Activity为一个程序的开始.比较常用. Input:nothing Outpu ...
- 深入理解async和await的作用及各种适用场景和用法
https://www.cnblogs.com/yaopengfei/archive/2018/07/02/9249390.html https://www.cnblogs.com/xianyudot ...
- UE4 集成讯飞听写插件
搞了几天,有些坑记录一下. 3个方面的知识需要学习 1.制作UE4插件 2.引入第三方库 3.讯飞听写的api 一看是参考 https://blog.csdn.net/u012793104/artic ...
- Excel工作常用(一)-生成序列与删除空行
整理一些工作中,本人经常用到的一些Excel操作 1.自动生成序列 [注]选择 第一格 和 第二格 之后,在右下角出现十字的时候,在往下拉 2.删除空行 方式一,先找出所有空行,在删 [缺点]数据多的 ...
- JS——void(0)
a标签中阻止跳转: <a href="javascript:;">跳转</a> <a href="javascript:void(0)&qu ...
- 六时出行 App iOS隐私政策
本应用尊重并保护所有使用服务用户的个人隐私权.为了给您提供更准确.更有个性化的服务,本应用会按照本隐私权政策的规定使用和披露您的个人信息.但本应用将以高度的勤勉.审慎义务对待这些信息.除本隐私权政策另 ...
- CSS中的disable,hidden,readonly
项目中有时候需要对某个input进行隐藏或者禁止修改等. 需要隐藏某个input的时候就用hidden <input hidden="true" > 如果要禁止修改in ...
- 12--c完数/最大公约数/最小公倍数/素数/回文数
完数/最大公约数/最小公倍数/素数/回文数 2015-04-08 10:33 296人阅读 评论(0) 收藏 举报 分类: C/C++(60) 哈尔滨工业大学(8) 版权声明:本文为博主原创文章 ...