POJ 1961 Period(KMP)

时间:2022-09-26 11:56:39

http://poj.org/problem?id=1961

题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数。

思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是KMP。

#include <string.h>
#include <stdio.h>
#include <iostream> using namespace std ; const int maxn = ; char ch[maxn] ;
int next[maxn] ; int main()
{
int n ;
int test = ;
while(scanf("%d%*c",&n)!=EOF)
{
if(n == ) break ;
scanf("%s",ch) ;
printf("Test case #%d\n",test) ;
test++ ;
int i = , j = - ;
next[] = - ;
while(i < n )
{
if(j == - || ch[i] == ch[j])
next[++i] = ++j ;
else
j = next[j] ;
}
int len ;
for(int k = ; k <= n ; k++)
{
len = k - next[k] ;
if(k != len && k % len == )
printf("%d %d\n",k,k / len) ;
}
printf("\n") ;
}
return ;
}

POJ 1961 Period(KMP)的更多相关文章

  1. LA 3026 &amp&semi;&amp&semi; POJ 1961 Period (KMP算法)

    题意:给定一个长度为n字符串s,求它每个前缀的最短循环节.也就是对于每个i(2<=i<=n),求一个最大整数k>1(如果存在),使得s的前i个字符组成的前缀是某个字符串重复得k次得到 ...

  2. poj 1961 Period(KMP训练指南例题)

    Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 11356   Accepted: 5279 Descripti ...

  3. POJ 1961 2406 (KMP,最小循环节,循环周期)

    关于KMP的最短循环节.循环周期,请戳: http://www.cnblogs.com/chenxiwenruo/p/3546457.html (KMP模板,最小循环节) POJ 2406  Powe ...

  4. Period(kmp)

    Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  5. HDU - 1358 - Period (KMP)

    Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  6. poj 3461 Oulipo(KMP)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49378   Accepted: 19617 Descript ...

  7. KMP POJ 1961 Period

    题目传送门 /* 题意:求一个串重复出现(>1)的位置 KMP:这简直和POJ_2406没啥区别 */ /******************************************** ...

  8. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  9. POJ 3414 Pots(罐子)

    POJ 3414 Pots(罐子) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 You are given two po ...

随机推荐

  1. Stopwatch 类

    Stopwatch 为计时器的实现. 主要属性方法 属性和方法 说明 static GetTimestamp() 如果Stopwatch使用高分辨率的性能计数器,则返回该计数器的当前值:如果Stopw ...

  2. WEB API 中HTTP的get、post、put&comma;delete 请求方式

    一.WEB API 中HTTP 请求方式的四个主要方法 (GET, PUT, POST, DELETE), 按照下列方式映射为 CURD 操作: 1.POST 用于新建资源,服务端在指定的URI 上创 ...

  3. java使用jacob将office转pdf

    1.此处代码是把office文档转换成pdf的工具类,在BS架构的产品中,我们可以使用基于JS的pdf插件显示pdf文档,但是前提IE需要按照adobe的pdf软件,对于非IE不用安装.2.可以基于f ...

  4. c语言与c&plus;&plus;基础知识

    1.后缀名: C++/C程序的头文件以.h为后缀,C程序的源文件以.c为后缀,C++程序的源文件通常以.cpp为后缀(有些书中介绍有一些系统以.cc或.cxx为后缀的源文件).在Linux系统下的gc ...

  5. Import the Add Email and Post Configuration to the SiteMap managed solution -Dynamices CRM

    We have prepared a managed solution named Add Email and Post Configuration to SiteMap that you can i ...

  6. javascript函数值的重写

    原文:javascript函数值的重写 javascript函数值的重写 定义了一个函数,需要重写这个函数并使用原先的函数值.做法是: 1.定义一个变量让原先函数的值指向它,把原先函数的指向一个新的函 ...

  7. Vue中父子组件通讯——组件todolist

    一.todolist功能开发 <div id="root"> <div> <input type="text" v-model=& ...

  8. Java线程基础(二)

    今天上午考完了计算机二级,也算卸掉了一个大包袱吧,希望能过!(其实也就考着玩的,不来点考试就要发霉了) 好了,趁着难得的考后休息时间我就接着上一次没写完的继续更新吧. 上一篇文章——>Java核 ...

  9. git 本地分支和远程分支改名字

    1.将本地分支进行改名: git branch -m old_branch new_branch 2.将本地分支的远程分支删除: git push origin :old_branch 3.将改名后的 ...

  10. CodeSmith的基础模版类(CodeSmith help中的内容)

    基础模版类类型描述: Batch      OutputFileCodeTemplate  模版通过继承此类能够在生成过程中把他们的输出保存到文件中 ScriptError    在脚本执行中出现一个 ...