链接:

https://vjudge.net/problem/FZU-1901

题意:

For each prefix with length P of a given string S,if

S[i]=S[i+P] for i in [0..SIZE(S)-p-1],

then the prefix is a “period” of S. We want to all the periodic prefixs.

思路:

求可能的循环节长度.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e6+10;
const int MOD = 1e4+7; char a[MAXN];
int Next[MAXN], Res[MAXN];
int n; void GetNext(char *s)
{
int len = strlen(s);
int j = 0, k = -1;
Next[0] = -1;
while (j < len)
{
if (k == -1 || s[j] == s[k])
{
++j;
++k;
Next[j] = k;
}
else
k = Next[k];
}
} int main()
{
int t, cnt = 0;
scanf("%d", &t);
while (t--)
{
scanf("%s", a);
int len = strlen(a);
GetNext(a);
int ans = 0;
int p = len;
while (p > 0)
{
Res[++ans] = len-Next[p];
p = Next[p];
}
printf("Case #%d: %d\n", ++cnt, ans);
printf("%d", Res[1]);
for (int i = 2;i <= ans;i++)
printf(" %d", Res[i]);
puts("");
} return 0;
}

FZU-1901-Period 2(KMP)的更多相关文章

  1. FZU - 1901 Period II(kmp所有循环节)

    Problem Description For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SI ...

  2. FZU 1901 Period II(KMP循环节+公共前后缀)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1901 题目大意:题目大意求出所有p满足s[i]=s[i+p](i<=len-p) 解题思路: 其实就是要 ...

  3. [FZU 1901]Period II KMP

    For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SIZE(S)-p-1], then the ...

  4. Fzu Problem 1901 Period II (kmp)

    题目链接: Problem 1901 Period II 题目描述: 给出一个串,满足长度为p的前缀和长度为p的后缀相等的p的个数,输出p的个数,和p分别是多少? 解题思路: 对kmp的next数组的 ...

  5. FZU - 1901 Period II (kmp)

    传送门:FZU - 1901 题意:给你个字符串,让你求有多少个p可以使S[i]==S[i+P] (0<=i<len-p-1). 题解:这个题是真的坑,一开始怎么都觉得自己不可能错,然后看 ...

  6. Period II FZU - 1901(拓展kmp)

    拓展kmp板题 emm...我比较懒 最后一个字母进了vector两个1  不想改了...就加了个去重... 哈哈 #include <iostream> #include <cst ...

  7. FZU 1901 Period II(KMP中的next)题解

    题意:给你一串字符串,问你前后缀相同情况有几种,并输出后缀位置(?这里一直没看懂length是什么,但是这样理解答案也对,然后还要加上本身长度) 思路:这里好好讲讲next的用法.我们都知道next代 ...

  8. (KMP Next的运用) Period II -- fzu -- 1901

    http://acm.fzu.edu.cn/problem.php?pid=1901 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=703 ...

  9. FZU1901 Period II —— KMP next数组

    题目链接:https://vjudge.net/problem/FZU-1901  Problem 1901 Period II Accept: 575    Submit: 1495Time Lim ...

  10. Period II - FZU 1901(KMP->next)

    题目大意:给你一个字符串 S ,N = |S|,如果存在一个 P (1<=P<=N),并且满足 s[i] = s[P+i] (i = {0...N-P-1} ),求出来所有的 P 然后输出 ...

随机推荐

  1. 获得http请求的RequestID

    firefox: F12---network---响应, 请求一个页面:

  2. [转帖]【架构系列】龙芯loongson简介

    [架构系列]龙芯loongson简介 https://blog.csdn.net/SoaringLee_fighting/article/details/97759305 2019年07月30日 10 ...

  3. Java基础题记录

    1. 装箱和拆箱 装箱:自动将基本数据类型转换为包装器类型即引用数据类型 拆箱:将包装器类型转换为基本数据类型 2. Java的8中基本数据类型 关键字 字节数 范围 默认值 boolelan 1by ...

  4. PAT A1036 Boys vs Girls(25)

    AC代码 #include <cstdio> #include <algorithm> using namespace std; const int max_n = 11000 ...

  5. windows环境下使用C++&Socket实现文件传输

    server #include <stdio.h> #include <iostream> #include <cstring> #include <fstr ...

  6. php 中文unicode 互转

    /** * $str 原始中文字符串 * $encoding 原始字符串的编码,默认GBK * $prefix 编码后的前缀,默认"&#" * $postfix 编码后的后 ...

  7. 老贾的第二天(git常用命令)

    git init #创建一个本地的仓库 **git add test.txt #指定文件添加 ***git add . #当前文件夹下所有内容 添加到暂存区 ***git commit -m &quo ...

  8. HORSE PILL--一种新型的linux rootkit

    资料 ppt:https://www.blackhat.com/docs/us-16/materials/us-16-Leibowitz-Horse-Pill-A-New-Type-Of-Linux- ...

  9. Java异常模块

    JAVA异常的捕获与处理 视频链接:https://edu.aliyun.com/lesson_1011_8939#_8939 java语言提供最为强大的支持就在于异常的处理操作上. 1,认识异常对程 ...

  10. Zend 3.3.0安装 ZendOptimizer 3.3.0 for Windows 稳定版 下载

    用的某php网站系统今天打开时乱码了(zend 200407...),但phpmyadmin能正常使用: 搜索下,重新安装zend可以解决,系统上原来的版本是Zend 3.3.0:下了个,安装后果然把 ...