题目传送门

 /*
题意:求一个串重复出现(>1)的位置
KMP:这简直和POJ_2406没啥区别
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-10 9:13:24
* File Name :POJ_1961.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
int n;
int nex[MAXN];
char str[MAXN]; void get_nex(void) {
int i = , j = -; nex[] = -;
while (i < n) {
if (j == - || str[j] == str[i]) {
j++; i++;
if (i % (i - j) == && i / (i - j) > ) {
printf ("%d %d\n", i, i / (i - j));
}
nex[i] = j;
}
else j = nex[j];
}
} int main(void) { //POJ 1961 Period
int cas = ;
while (scanf ("%d", &n) == ) {
if (!n) break;
scanf ("%s", &str);
printf ("Test case #%d\n", ++cas);
get_nex ();
puts ("");
} return ;
}

KMP POJ 1961 Period的更多相关文章

  1. POJ 1961 Period( KMP )*

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

  2. POJ 1961 Period(KMP)

    http://poj.org/problem?id=1961 题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数. 思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是K ...

  3. POJ 1961 Period KMP算法next数组的应用

    题目: http://poj.org/problem?id=1961 很好的题,但是不容易理解. 因为当kmp失配时,i = next[i],所以错位部分就是i - next[i],当s[0]...s ...

  4. (简单) POJ 1961 Period,扩展KMP。

    Description For each prefix of a given string S with N characters (each character has an ASCII code ...

  5. KMP——POJ-3461 Oulipo && POJ-2752 Seek the Name, Seek the Fame && POJ-2406 Power Strings && POJ—1961 Period

    首先先讲一下KMP算法作用: KMP就是来求在给出的一串字符(我们把它放在str字符数组里面)中求另外一个比str数组短的字符数组(我们叫它为ptr)在str中的出现位置或者是次数 这个出现的次数是可 ...

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

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

  7. LA 3026 && POJ 1961 Period (KMP算法)

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

  8. POJ 1961 Period KMP算法之next数组的应用

    题意:给一个长度为n的字符串,如果它长度为l(2 <= l <= n)的前缀部分是由一些相同的字符串相接而成,输出前缀的长度l和长度为l时字符串重复的最大次数. 例如字符串为: aaaba ...

  9. poj 1961 Period

    Period http://poj.org/problem?id=1961 Time Limit: 3000MS   Memory Limit: 30000K       Description Fo ...

随机推荐

  1. 网络编程进阶:并发编程之协程、IO模型

    协程: 基于单线程实现并发,即只用一个主线程(此时可利用的CPU只有一个)情况下实现并发: 并发的本质:切换+保存状态 CPU正在运行一个任务,会在两种情况下切走去执行其他任务(切换有操作系统强制控制 ...

  2. android开发里跳过的坑-AS导入NDK工程提示错误 No such property: sdkHandler for class: com.android.build.gradle.LibraryPlugin

    接到一个NDK工程需要调试,导入后发现总是提示错误 Error:(37, 1) A problem occurred evaluating project ':libuvccamera'.> N ...

  3. Mysql Replace语句的使用

    Mysql Replace语句的语法: REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name [(col_name,...)] VALUES ({expr ...

  4. 【HDOJ3341】Lost's revenge(AC自动机,DP)

    题意:给出一个n个模式串,一个目标串,问把目标串重新排位最多能产生多少个模式串,可以重叠且所有串只包含A C G T. n<=10,len[i]<=10 len(s)<=40 Cas ...

  5. Linux下汇编语言学习笔记1 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  6. spring boot项目自定义数据源,mybatisplus分页、逻辑删除无效解决方法

    Spring Boot项目中数据源的配置可以通过两种方式实现: 1.application.yml或者application.properties配置 2.注入DataSource及SqlSessio ...

  7. SpringBoot常用注解总结

    在SpringBoot框架中,注解做为一种隐式配置,极大的简化了之前xml文件的配置方式.SpringBoot中包含许多种类的注解,这里对在SpingBoot项目中经常使用到的一些注解的进行大致的归纳 ...

  8. linux复制文件/移动文件从一个文件夹到另一个文件夹

    cp ~/baidu/* ~/zhidao/cp -r逐层复制mv /data/link /usr/local 移动文件夹 解决方法 1.在cp命令后,加一个选项 -r . cp -r  /TEST/ ...

  9. #!/usr/bin/env 脚本解释程序的作用

    the Zimbu programming language http://www.zimbu.org/getting-started -------------------------------- ...

  10. JSTL简单入门学习实例

    Maven依赖: <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</ ...