KMP POJ 1961 Period
/*
题意:求一个串重复出现(>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的更多相关文章
- POJ 1961 Period( KMP )*
Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...
- POJ 1961 Period(KMP)
http://poj.org/problem?id=1961 题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数. 思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是K ...
- POJ 1961 Period KMP算法next数组的应用
题目: http://poj.org/problem?id=1961 很好的题,但是不容易理解. 因为当kmp失配时,i = next[i],所以错位部分就是i - next[i],当s[0]...s ...
- (简单) POJ 1961 Period,扩展KMP。
Description For each prefix of a given string S with N characters (each character has an ASCII code ...
- 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中的出现位置或者是次数 这个出现的次数是可 ...
- poj 1961 Period(KMP训练指南例题)
Period Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 11356 Accepted: 5279 Descripti ...
- LA 3026 && POJ 1961 Period (KMP算法)
题意:给定一个长度为n字符串s,求它每个前缀的最短循环节.也就是对于每个i(2<=i<=n),求一个最大整数k>1(如果存在),使得s的前i个字符组成的前缀是某个字符串重复得k次得到 ...
- POJ 1961 Period KMP算法之next数组的应用
题意:给一个长度为n的字符串,如果它长度为l(2 <= l <= n)的前缀部分是由一些相同的字符串相接而成,输出前缀的长度l和长度为l时字符串重复的最大次数. 例如字符串为: aaaba ...
- poj 1961 Period
Period http://poj.org/problem?id=1961 Time Limit: 3000MS Memory Limit: 30000K Description Fo ...
随机推荐
- DRF JWT的用法 & Django的自定义认证类 & DRF 缓存
JWT 相关信息可参考: https://www.jianshu.com/p/576dbf44b2ae DRF JWT 的使用方法: 1. 安装 DRF JWT # pip install djang ...
- 详解SpringBoot 添加对JSP的支持(附常见坑点)
序言: SpringBoot默认不支持JSP,如果想在项目中使用,需要进行相关初始化工作.为了方便大家更好的开发,本案例可直接作为JSP开发的脚手架工程 SpringBoot+War+JSP . 常见 ...
- 创建Django项目(一)
2013-07-24 23:20:58| 最近在学习Django项目的创建,主要的参考资料是:Djangobook 和 Django Project.这些日志用来记录自己的学习过程吧. ...
- Java ThreadLocal 使用详解
ThreadLocal的官方API解释为: "该类提供了线程局部 (thread-local) 变量.这些变量不同于它们的普通对应物,因为访问某个变量(通过其 get 或 set 方法)的每 ...
- OJ(Online Judge)
OJ:它是Online Judge系统的简称,用来在线检测程序源代码的正确性.著名的OJ有RQNOJ.URAL等.国内著名的题库有北京大学题库.浙江大学题库等.国外的题库包括乌拉尔大学.瓦拉杜利德大学 ...
- react 执行 yarn build 页面无法显示
资源文件路径问题 如果你使用create-react-app创建项目,执行命令 yarn build 后,直接以静态方式打开build文件夹内的index.html,会看到页面显示出现问题,打开con ...
- hdu 3006 The Number of set(思维+壮压DP)
The Number of set Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 南阳oj 语言入门 A+B paoblem 题目477 题目844
A+Bproblem 题目844 两个数字翻转后相加 比方10+12 翻转后01+21=22 #include<stdio.h> int main() { int ji(in ...
- 什么是sibling and tail recursive calls
1 tail call 在函数f中调用函数b,如果这个调用是函数f中执行的最后一条指令,那么这个调用就称为tail call. 例子: int foo(float a, float b) { ... ...
- shell 爬虫 从日志分析到数据采集与分析
[root@VM_61_158_centos ~]# curl http://ip.chinaz.com/220.112.233.179 |grep -e Whwtdhalf.*span.*span. ...