链接:

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. (转)新手入局 你必须要知道的四类Equity

    许多人缠着我教他们打牌,开始几乎所有的问题都是问,你都玩什么牌. 这个话外行又很难解释,想来想去,我这样总结给他们(我也忘记自己过去有没有说过,我觉得总结的挺好的,只怕初学者听着又和天书一样了). 是 ...

  2. Jenkins+Github持续环境搭建

    ⒈前提要求 Jenkins与Github配合实现持续集成需要注意以下几点: 1.Jenkins需要部署在外网上,因为内网地址是无法访问Github的.这一点可以通过租用阿里云.腾讯云等云平台提供的云服 ...

  3. VS添加版权声明

    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ItemTemplates\AspNetCore\ ...

  4. centos编译安装python3怎么做?

    照着我的博客操作 你一定能成功的!因为我就是一步一步的做出来的,虽然只有文档,但是希望你能有耐心!!!! 编译安装难么麻烦,为什么还要编译安装? 那我告诉你想进步就要折腾!你习惯了windows的安装 ...

  5. js,bom,dom(相信我,你看不懂我写的)

    js dom bom 2种结合方式: 1.在body中加入script标签,<script type="text/javascript" >alert(" 向 ...

  6. asp.net练习②——Paginaton无刷新分页

    aspx代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server" ...

  7. C#面向对象19 值传递和引用传递

    值类型:int double char decimal bool enum struct引用类型:string 数组 自定义类 集合 object 接口 **值传递和引用传递1.值类型在复制的时候,传 ...

  8. 对接外网post,get接口封装类库

    public class HttpHelper { public static string GetAsync(string url)  { HttpWebRequest request = WebR ...

  9. 服务端相关知识学习(四)之Zookeeper启动过程

    在上一篇,我们了解了zookeeper最基本的配置,也从中了解一些配置的作用,那么这篇文章中,我们将介绍Zookeeper的启动过程,我们在了解启动过程的时候还要回过头看看上一篇中各个配置参数在启动时 ...

  10. UVA571Jugs题解--简单数论(其实是瞎搞)

    题目链接 https://cn.vjudge.net/problem/UVA-571 分析 刚做了道倒水问题的题想看看能不能水二倍经验,结果发现了这道题 题意翻译:https://www.cnblog ...