uvalive3026:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1027

题解:给你一个串,然后让你找出前缀中是周期串的位子以及循环的次数。

题解:刚接触KMP,知道了KMP中的next数组可以解决这个问题。对一个串来说,如果这个串是周期串。那么,i-next[i]就是该串的循环节,反之亦然。即,(i-next[i])*k=i;

则,该串是周期串。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e7+;
char p[N];
int f[N];
int main(){
int n,kase=;
while(~scanf("%d",&n)&&n){
scanf("%s",p);
printf("Test case #%d\n",++kase);
f[]=;f[]=;
for(int i=;i<n;i++){
int j=f[i];
while(j&&p[i]!=p[j])j=f[j];
f[i+]=(p[i]==p[j]?j+:);
//printf("*%d ",f[i]);
}
for(int i=;i<=n;i++){
if(f[i]>&&i%(i-f[i])==) printf("%d %d\n",i,i/(i-f[i]));
}
printf("\n");
}
}

Period的更多相关文章

  1. TCP Provider The semaphore timeout period has expired

    我们一数据库服务器上有个作业最近几天偶尔会遇到下面错误(敏感信息已做处理),主要是报"TCP Provider: The semaphore timeout period has expir ...

  2. SSRS 2008 R2 错误:Timeout expired. The timeout period

    今天遇到了Reporting Services(SQL SERVER 2008 R2)的报表执行异常情况,报表加载数据很长时间都没有响应,最后报"An error occurred with ...

  3. Clock Skew , Clock Uncertainty和 Period

    本文将介绍FPGA中和时钟有关的相关概念,阅读本文前需要对时序收敛的基本概念和建立.保持关系有一定了解,这些内容可以在时序收敛:基本概念,建立时间和保持时间(setup time 和 hold tim ...

  4. 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. ...

  5. Match:Period(POJ 1961)

    Period 题目大意:给定一个字符串,要你找到前缀重复了多少次 思路,就是kmp的next数组的简单应用,不要修正next的距离就好了,直接就可以跳转了 PS:喝了点酒用递归实现除法和取余了...结 ...

  6. cargo failed to finish deploying within the timeout period [120000]

    cargo插件,报错:failed to finish deploying within the timeout period [120000] 解决方法:配置timeout为0 <plugin ...

  7. Date get period

    /** * get period for last year * @param time * @return */ public static DatePeriodDTO getLastYear(lo ...

  8. Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

    今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者 如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" ...

  9. POJ 1961 Period( KMP )*

    Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...

  10. [LA3026]Period

    [LA3026]Period 试题描述 For each prefix of a given string S with N characters (each character has an ASC ...

随机推荐

  1. Unity3D 画线插件 Vectrosity 画一个一直循环的正弦函数曲线

    直接贴代码 public Material myMaterisl; float fx;//曲线最左边的X坐标 float fy;//曲线趋于直线时y轴坐标 float fyMax = 0f;//曲线最 ...

  2. CSU1661: Query Mutiple

    Description One day,Little-Y saw many numbers standing in a row. A question suddenly appeared in her ...

  3. 改写URL的查询字符串QUERY_STRING(转)

    查询字符串是指URL请求中“问号”后面的部分.比如,http://www.nowamagic.net/?foo=bar中粗体部分就是查询字符串,其中变量名是foo,值是bar. 1. 利用QSA转换查 ...

  4. 独立硬盘冗余阵列与HDFS

    http://zh.wikipedia.org/wiki/RAID 独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(Re ...

  5. (转)H264(NAL简介与I帧判断)

    1.NAL全称Network Abstract Layer, 即网络抽象层.         在H.264/AVC视频编码标准中,整个系统框架被分为了两个层面:视频编码层面(VCL)和网络抽象层面(N ...

  6. 【开源java游戏框架libgdx专题】-07-文件处理

    介绍:文件处理在不同平台的文件管理是略有差异的 Desktop(Windows,Linux,Mac OS X等等):在桌面系统中,文件系统是一个大块的内存.文件可以通过当前的工作目录或者绝对路径被引用 ...

  7. XML在JAVA项目中的作用

    java项目中,xml文件一般都是用来存储一些配置信息 一般的编程, 多数用来存储配置信息 . 拿JDBC来说,可以把数据库连接字符串写到xml,如果要修改数据源,只需要改xml就可以了,没必要再去重 ...

  8. [转载]使用兼容ie6 ie7 ie8 FF的text-overflow:ellips

    使用兼容ie6 ie7 ie8 FF的text-overflow:ellipsis超出文本显示省略号来代替截取函数更有利于seo,如果使用截取函数,源代码中的标题是显示不完整的,即便是在title属性 ...

  9. CXF处理Date类型的俩种方式

    1. CXF利用wsdl2java生成客户端时Date日期类型转换 http://cwfmaker.iteye.com/blog/1142835 2. GregorianCalendar cal = ...

  10. Mavne + Spring整合CXF

    http://blog.csdn.net/xiongyu777888/article/details/23787615(没毛病) http://blog.csdn.net/hbsong75/artic ...