Problem Description

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.

 Input

Input contains multiple cases.

The first line contains an integer T representing the number of cases. Then following T cases.

Each test case contains a string S (1 <= SIZE(S) <= 1000000),represents the title.S consists of lowercase ,uppercase letter.

 Output

For each test case, first output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of periodic prefixs.Then output the lengths of the periodic prefixs in ascending order.

 Sample Input

4
ooo
acmacmacmacmacma
fzufzufzuf
stostootssto

 Sample Output

Case #1: 3
1 2 3
Case #2: 6
3 6 9 12 15 16
Case #3: 4
3 6 9 10
Case #4: 2
9 12
 
题意:求出一个字符串的所有可能循环节的长度
思路:kmp的运用,题目的意思不是很清楚 j=next[j] 就是次大的匹配个数
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define ll long long int
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int nextt[];
void getnext(string s){
nextt[]=; int len=s.length();
for(int i=,j=;i<=len;i++){
while(j>&&s[i-]!=s[j]) j=nextt[j];
if(s[i-]==s[j]) j++;
nextt[i]=j;
}
}
int main(){
ios::sync_with_stdio(false);
int t;
cin>>t;
int w=;
while(t--){
string s;
cin>>s;
getnext(s);
int len=s.length();
queue<int> q;
int j=nextt[len];
while(j>){
q.push(j);
j=nextt[j];
}
q.push();
bool f=;
cout<<"Case #"<<++w<<": "<<q.size()<<endl;
while(!q.empty()){
int temp=q.front();
q.pop();
if(f){
cout<<len-temp;
f=;
}else{
cout<<" "<<len-temp;
}
}
cout<<endl;
}
return ;
}

FZU - 1901 Period II(kmp所有循环节)的更多相关文章

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

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

  2. [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 ...

  3. Fzu Problem 1901 Period II (kmp)

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

  4. FZU - 1901 Period II (kmp)

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

  5. HDU 1358 Period(KMP+最小循环节)题解

    思路: 这里只要注意一点,就是失配值和前后缀匹配值的区别,不懂的可以看看这里,这题因为对子串也要判定,所以用前后缀匹配值,其他的按照最小循环节做 代码: #include<iostream> ...

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

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

  7. HDU 3746 Cyclic Nacklace (KMP求循环节问题)

    <题目链接> 题目大意: 给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数. [>>>kmp next函数 kmp的周期问题]  #include &l ...

  8. FZU1901 Period II —— KMP next数组

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

  9. HDU 1358 Period (kmp求循环节)(经典)

    <题目链接> 题目大意: 意思是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第 ...

随机推荐

  1. 开发环境搭建(lnmp)

    我们的开发环境一般现在时用Linux + Nginx + MySQL(mariaDB) + PHP的组合进行项目的搭建与开发,工欲善其事必先利其器. 搭建环境: Centos7 + mysql5.6 ...

  2. Git - 常见错误与解决方案

    1.windows使用git时出现:warning: LF will be replaced by CRLF 分析: windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行 ...

  3. [转帖]整理:Windows系统下的奇技淫巧大汇总

    整理:Windows系统下的奇技淫巧大汇总 https://blog.csdn.net/bat67/article/details/76381357 Win+home Crtl+home 还有 Win ...

  4. Python 基础知识----数据类型

    一.Number 类型(数值类型) 二.String 类型 (字符串类型) 三.List 类型 (列表类型) 是一种常用的序列类型簇,List 用中括号 [ ] 表示,不同的元素(任意类型的值)之间以 ...

  5. jenkins的 git多分支自动构建

    一.先做好jenkins和gitlab的webhook自动构建 二.选择哪个分支(我这是test分支) 三.选择build Triggers 四.过滤test分支 五.保存即可

  6. 八、.net core 通过数据库配置文件连接操作数据库

    一.创建DotNetCore项目 直接创建core项目并不勾选docker支持  二.nuget进行连接MySQL程序集的下载安装 1.MySql.Data.EntityFrameworkCore方式 ...

  7. Lodop部署web网站 客户端本地打印角色

    Lodop用于客户端本地打印,部署到web网站非常简单,此博文介绍的是混合部署方式,该方式兼容所有浏览器,当浏览器支持np插件的时候,使用Lodop插件方式,浏览器不支持np插件,会用C-Lodop服 ...

  8. ES 6 系列 - Module 的语法

    es 6 大幅度优化了模块化编程的规范. 写在前面:在 es6 之前,说起 js 的模块化,一般都避不开 CommonJs 和 AMD 两种方案.这两种方案,前者应用于服务器,后者应用于浏览器.而 e ...

  9. 安装mysql zip5.7版--安裝

    一直以来都习惯了使用MySQL安装文件(.exe),今天下载了一个.zip版本的MySQL,安装过程中遇到了一些问题,如下: 1.在MySQL官网上(http://dev.mysql.com/down ...

  10. 5.cgroup资源控制

    控制组( CGroups)是 Linux 内核的一个特性,主要用来对共享资源进行隔离.限制.审计等. 只有将分配到容器的资源进行控制,才能避免多个容器同时运行时对宿主机系统的资源竞争.每个控制组是一组 ...