链接:https://www.nowcoder.com/acm/contest/141/E

题目描述

Eddy likes to play with string which is a sequence of characters. One day, Eddy has played with a string S for a long time and wonders how could make it more enjoyable. Eddy comes up with following procedure:

1. For each i in [0,|S|-1], let Si be the substring of S starting from i-th character to the end followed by the substring of first i characters of S. Index of string starts from 0.
2. Group up all the Si. Si and Sj will be the same group if and only if Si=Sj.
3. For each group, let Lj be the list of index i in non-decreasing order of Si in this group.
4. Sort all the Lj by lexicographical order.

Eddy can't find any efficient way to compute the final result. As one of his best friend, you come to help him compute the answer!

输入描述:

Input contains only one line consisting of a string S.

1≤ |S|≤ 10

6

S only contains lowercase English letters(i.e. 

).

输出描述:

First, output one line containing an integer K indicating the number of lists.
For each following K lines, output each list in lexicographical order.
For each list, output its length followed by the indexes in it separated by a single space.

输入例子:
abab
输出例子:
2
2 0 2
2 1 3

-->

示例1

输入

abab

输出

2
2 0 2
2 1 3
示例2

输入

deadbeef

输出

8
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7

题意   给定一个字符串T 设长度为n   然由这个字符串产生出n个字符串s0...sn-1  si=Ti-Tn-1+T0-Ti-1 将si相同的分到一组   i 按照从小到大排序 输出分组后的 i 序列

解析   我们可以推导一下 若T是不循环的 那么没有相同的  若是循环的 最小循环节为len 那么共有len 组   i 就属于 i%len这一组

   KMP判断是否循环 且找出最小循环节长度  随便 保存一下 也可以哈希。。。

 #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n");
#define debug(a,b) cout<<a<<" "<<b<<" ";
using namespace std;
typedef long long ll;
const int maxn=1e6+,inf=0x3f3f3f3f;
const ll mod=1e9+;
char t[maxn];
int _next[maxn];
int tlen,slen;
void getnext()
{
int j,k;
j=,k=-,_next[]=-;
while(j<=tlen)
if(k==-||t[j]==t[k])
_next[++j]=++k;
else
k=_next[k];
}
int main()
{
while(scanf("%s",t)!=EOF)
{
tlen=strlen(t);
set<int> s[tlen+];
getnext();
if(tlen%(tlen-_next[tlen])==)
{
int len=tlen-_next[tlen];
for(int i=;i<tlen;i++)
s[i%len].insert(i);
printf("%d\n",len);
for(int i=;i<len;i++)
{
printf("%d",s[i].size());
for(auto it=s[i].begin();it!=s[i].end();it++)
{
printf(" %d",*it);
}
huan;
}
}
else
{
printf("%d\n",tlen);
for(int i=;i<tlen;i++)
printf("%d %d\n",,i);
}
}
}

牛客网 牛客网暑期ACM多校训练营(第三场)E KMP的更多相关文章

  1. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  2. 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学

    牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...

  3. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  4. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)

    链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  5. 牛客网暑期ACM多校训练营(第九场) A题 FWT

    链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...

  6. 牛客网暑期ACM多校训练营(第九场)D

    链接:https://www.nowcoder.com/acm/contest/147/D来源:牛客网 Niuniu likes traveling. Now he will travel on a ...

  7. 牛客网暑期ACM多校训练营(第二场)B discount

    链接:https://www.nowcoder.com/acm/contest/140/B来源:牛客网 题目描述 White Rabbit wants to buy some drinks from ...

  8. 2018牛客网暑期ACM多校训练营(第一场)D图同构,J

    链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...

  9. 牛客网暑期ACM多校训练营(第二场) I Car 思维

    链接:https://www.nowcoder.com/acm/contest/140/I来源:牛客网 White Cloud has a square of n*n from (1,1) to (n ...

  10. 牛客网暑期ACM多校训练营(第二场) D money 思维

    链接:https://www.nowcoder.com/acm/contest/140/D来源:牛客网 White Cloud has built n stores numbered from 1 t ...

随机推荐

  1. iOS infoq资料架构设计漫谈

    http://www.infoq.com/cn/ios/?utm_source=infoq&utm_medium=header_graybar&utm_campaign=topic_c ...

  2. PHP Deprecated: Function split() is deprecated in /var/www/html/cacti/cmd.php on line 61

    [root@localhost cacti]# php cmd.php PHP Deprecated: Function split() is deprecated in /var/www/html/ ...

  3. 通过HA方式操作HDFS

    之前操作hdfs的时候,都是固定namenode的地址,然后去操作.这个时候就必须判断namenode的状态为active还是standby,比较繁琐,如果集群使用了HA的形式,就很方便了 直接上代码 ...

  4. Javaweb学习笔记6—EL表达式与JSTL及自定义标签

    今天来讲javaweb的第六阶段学习. EL表达式与JSTL及自定义标签是对上篇文章介绍的JSP的扩展,不能说是很重要的东西,但是也要了解. 老规矩,首先先用一张思维导图来展现今天的博客内容. ps: ...

  5. vue下axios和fetch跨域请求

    1.在config的index.js下面进行常用跨域配置代码:proxyTable: { '/apis': { //使用"/api"来代替"http://xxxx.cn& ...

  6. Recyclerview设置间距

    首先自定义一个RecyclerViewDivider 继承 RecyclerView.ItemDecoration,实现自定义. public class RecyclerViewDivider ex ...

  7. Spring AOP源码解析——专治你不会看源码的坏毛病!

    昨天有个大牛说我啰嗦,眼光比较细碎,看不到重点.太他爷爷的有道理了!要说看人品,还是女孩子强一些. 原来记得看到一个男孩子的抱怨,说怎么两人刚刚开始在一起,女孩子在心里就已经和他过完了一辈子.哥哥们, ...

  8. 阿里P7/P8学习路线图——技术封神之路

    一.基础篇 JVM JVM内存结构 堆.栈.方法区.直接内存.堆和栈区别 Java内存模型 内存可见性.重排序.顺序一致性.volatile.锁.final 垃圾回收 内存分配策略.垃圾收集器(G1) ...

  9. CentOS6 自己动手搭建开放NTP服务器

    第一步: 1. 安装NTP服务程序: [root@host ~]# rpm -qa | grep ntp #查询是否安装ntp服务程序 [root@host ~]# yum install -y nt ...

  10. OpenCV2:第一章 图像表示

    一.简介 在OpenCV中,可以用C++语法的Mat类来表示一张图像 也可以用C语法的lpllmage或CvMat结构体来表示一张图像 1.单通道像素值 2.多通道像素值 OpenCV默认颜色顺序为B ...