POJ 1961 Period(KMP)
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)的更多相关文章
- LA 3026 && POJ 1961 Period (KMP算法)
题意:给定一个长度为n字符串s,求它每个前缀的最短循环节.也就是对于每个i(2<=i<=n),求一个最大整数k>1(如果存在),使得s的前i个字符组成的前缀是某个字符串重复得k次得到 ...
- poj 1961 Period(KMP训练指南例题)
Period Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 11356 Accepted: 5279 Descripti ...
- POJ 1961 2406 (KMP,最小循环节,循环周期)
关于KMP的最短循环节.循环周期,请戳: http://www.cnblogs.com/chenxiwenruo/p/3546457.html (KMP模板,最小循环节) POJ 2406 Powe ...
- Period(kmp)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU - 1358 - Period (KMP)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- poj 3461 Oulipo(KMP)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 49378 Accepted: 19617 Descript ...
- KMP POJ 1961 Period
题目传送门 /* 题意:求一个串重复出现(>1)的位置 KMP:这简直和POJ_2406没啥区别 */ /******************************************** ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- POJ 3414 Pots(罐子)
POJ 3414 Pots(罐子) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 You are given two po ...
随机推荐
- createjs 使用记录
createjs由几个库组成: l,easeljs,这个是核心,包括了显示列表.事件机制: 2,preloadjs,用于预加载图片等: 3,tweenjs,用于控制元件的缓动: 4,soundjs,用 ...
- scala学习笔记:控制抽象
def repeat(n:Int)(action: =>Unit)=for(i<-1 to n)action var i = 0 repeat(5){ println(i=i+1) } 另 ...
- ASP缓存类收集
木鸟写的 '********************************************** ' vbs Cache类 ' ' 属性valid,是否可用,取值前判断 ' 属性name,ca ...
- 如何覆盖aar的资源
1.首先理解一下aar的构造 classes.jar ----代码 res---资源文件 2.替换 查看res里面的资源文件,这个资源文件事实上都是跟安卓的资源文件夹是一样的.你只需要理解xml和里面 ...
- Android开发之Service
什么是Service? Android中的服务与Activity不同,他是不能与用户进行交互,自己也不能启动在后台运行的程序,当我们退出应用时,Service应用并没有结束,它仍然在后台运行. 例子: ...
- oracle 11G创建表空间、用户、配置监听和TNS
最近总在安装各种版本的oralce数据库做测试,11G,32位的,64位的,12C的,每次都折腾表空间,用户.tns啥的,这里记录下,再也不用现用现百度找了 一.创建表空间.用户 在plsql工具中 ...
- 在Xcode6中找回失去的模板
[Add]2014.07.27 添加OC category.protocol模板 Xcode 6从beta 3开始在创建新项目窗口中移除了“Empty Application”,如下: 其他选项很不幸 ...
- 对于jfinal中java.lang.Long cannot be cast to java.lang.Integer的解决方法
@Jfinal 老大提供的解决方法 当数据库字段为 int 型(有符号int型),但是如果在 sql 中使用了某些函数,jdbc 会自动转型为 long,例如:select sum(money) fr ...
- jquery之each
$.each()与$(selector).each()不同, 后者专用于jquery对象的遍历, 前者可用于遍历任何的集合(无论是数组或对象),如果是数组,回调函数每次传入数组的索引和对应的值(值亦可 ...
- 19_高级映射:一对多查询(使用resultMap)
[需求] 查询订单以及订单明细的信息. 确定主查询表:订单表orders 确定关联查询表:订单明细表 orderdetail 在一对一查询的基础上添加订单明细表关联即可. [分析] 使用resultM ...