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. servelt乱码问题(tomcat服务端编码为ISO-8859-1)

    Post的编码决定机制: <meta http-equiv="Content-Type" content="text/html; charset=gb2312&qu ...

  2. Monkey log分析说明

    运行命令: adb shell monkey -p com.crazyhornets.MyHokageAndroidZSY -v -v -v 20 -- throttle 1000 Log: :Mon ...

  3. UIScrollView控件详解

    一.知识点简单介绍 1.UIScrollView控件是什么? (1)移动设备的屏幕⼤大⼩小是极其有限的,因此直接展⽰示在⽤用户眼前的内容也相当有限 (2)当展⽰示的内容较多,超出⼀一个屏幕时,⽤用户可 ...

  4. VC++获取网卡MAC、硬盘序列号、CPU ID、BIOS编号

    以下代码可以取得系统特征码(网卡MAC.硬盘序列号.CPU ID.BIOS编号) BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码 UINT uSys ...

  5. 不用jquery等框架实现ajax无刷新登录

    <script type="text/javascript"> window.onload = function () { document.getElementByI ...

  6. 1、第1课.net学习2150916

    HTML标签 1.<p> <p> 标签 段落标签 2.<h1-6></h1> 文字标签从1-6 3. <i></i> 斜体 &l ...

  7. css渐变色

    <!DOCTYPE html><html><head> <meta http-equiv="content-type" content=& ...

  8. struts2学生信息管理系统篇章③

    package com.java1234.util; public class PageUtil { //传进来四个参数,tagetUtil是跳转链接的头部,totalNum是总个数,currentP ...

  9. 初定为EGame

    [Q]在纠结到底要用什么方式写博客,是原生态记录框架编写过程(有点所谓的手把手教学的感觉有木有),还是每个模块整合完毕后写分析文章,新手没有写过博客,不知道那种效果好.朋友们给点建议? 这套框架的初衷 ...

  10. node.js动态调试

    supervisor node ./bin/www npm start 不会动态运行和调试程序,相当于动态部署