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 && 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. yii下使用oracle中文都变成问号乱码的解决方法

    在配置文件中,一般会用以下配置: 'db_oracle'=>array( 'class' => 'CDbConnection', 'connectionString'=>'oci:d ...

  2. Android的几种alert对话框

    @Override public void onClick(View v) { switch (v.getId()) { case R.id.d1: AlertDialog.Builder build ...

  3. 蓝牙 GameKit

    一.准备工作 1.搭建UI  2.拖线 // 图片 @property (weak, nonatomic) IBOutlet UIImageView *imageView; // 建立连接 - (IB ...

  4. CSS常用布局实现方法

    CSS 布局对我来说,既熟悉又陌生.我既能实现它,又没有很好的了解它.所以想总结一下,梳理一下 CSS 中常用的一列,两列,三列布局等的实现方法.本文小白,仅供参考.但也要了解下浮动,定位等. 一.一 ...

  5. ACM——01排序

    http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1024 01排序 时间限制(普通/Jav ...

  6. Exam 70-462 Administering Microsoft SQL Server 2012 Databases 复习帖

    好吧最近堕落没怎么看书,估计这个月前是考不过了,还是拖到国庆之后考试吧.想着自己复习考试顺便也写点自己的复习的概要,这样一方面的给不准备背题库的童鞋有简便的复习方法(好吧不被题库的同学和我一样看MSD ...

  7. Swift学习的新工具---REPL

    从xcode6.1开始,苹果官方提供了一个新的辅助开发swift的工具,即repl(read eval print loop) OS X Yosemite系统下,打开终端应用程序,输入swift: 如 ...

  8. UVA - 572 Oil Deposits(dfs)

    题意:求连通块个数. 分析:dfs. #include<cstdio> #include<cstring> #include<cstdlib> #include&l ...

  9. JavaScript实现点击按钮弹出输入框,点确定后添加li组件到ul组件里

    JavaScript实现点击按钮弹出输入框,点确定后添加li组件到ul组件里 <!doctype html> <html manifest="lab4.manifest&q ...

  10. 在ctex环境下利用Metapost作图

    使用Metapost作图,是LaTeX的好搭档.下面介绍如何在ctex环境下的使用Metapost作图. 首先新建一个test.mp的Metapost文件. 在文件开始需要声明如下代码: prolog ...