链接: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: . For each i in [,|S|-], 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 .
. Group up all the Si. Si and Sj will be the same group if and only if Si=Sj.
. For each group, let Lj be the list of index i in non-decreasing order of Si in this group.
. 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. ≤ |S|≤
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.
示例1
输入 复制
abab
输出 复制 示例2
输入 复制
deadbeef
输出 复制

字符串哈希超时,还是太菜看到大佬用unordered map写哈希过了,

kmp 求循环节;

#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long
#define maxn 1000010
char s[maxn];
int len, Next[maxn];
void makeNext(int tlen) {
int j = , k = -;
Next[] = -;
while (j < tlen) {
if (k == - || s[j] == s[k]) {
Next[++j] = ++k;
} else {
k = Next[k];
}
}
} int main()
{
cin>>s;
len=strlen(s);
makeNext(len);
int x=len-Next[len];
if (len % x!= ) {
printf("%d",len);
for(int i = ; i < len; i++) {
printf("1 %d\n",i);
}
}
else {
printf("%d\n",x);
for(int i = ; i < x; i++) {
printf("%d",len/x);
for(int j = i; j < len; j += x)
printf(" %d",j);
printf("\n");
}
} return ;
}

牛客网多校第3场Esort string (kmp)的更多相关文章

  1. 牛客网多校第3场C-shuffle card 平衡树或stl(rope)

    链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...

  2. 牛客网多校赛第九场A-circulant matrix【数论】

    链接:https://www.nowcoder.com/acm/contest/147/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  3. 牛客网多校训练第二场D Kth Minimum Clique

    链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...

  4. 牛客网多校第5场 H subseq 【树状数组+离散化】

    题目:戳这里 学习博客:戳这里 题意:给n个数为a1~an,找到字典序第k小的序列,输出该序列所有数所在位置. 解题思路:先把所有序列预处理出来,方法是设一个数组为dp,dp[i]表示以i为开头的序列 ...

  5. 牛客网多校第5场 I vcd 【树状数组+离散化处理】【非原创】

    题目:戳这里 学习博客:戳这里 作者:阿狸是狐狸啦 n个点,一个点集S是好的,当且仅当对于他的每个子集T,存在一个右边无限延长的矩形,使的这个矩形包含了T,但是和S-T没有交集. 求有多少个这种集合. ...

  6. 牛客网多校第4场 J Hash Function 【思维+并查集建边】

    题目链接:戳这里 学习博客:戳这里 题意: 有n个空位,给一个数x,如果x%n位数空的,就把x放上去,如果不是空的,就看(x+1)%n是不是空的. 现在给一个已经放过数的状态,求放数字的顺序.(要求字 ...

  7. 牛客网多校第4场 A.Ternary String 【欧拉降幂】

    题目:戳这里 学习博客:戳这里 欧拉函数的性质: ① N是不为0的整数.φ(1)=1(唯一和1互质的数就是1本身) ② 除了N=2,φ(N)都是偶数. ③ 小于N且与N互质的所有数的和是φ(n)*n/ ...

  8. 牛客网多校训练第一场 J - Different Integers(树状数组 + 问题转换)

    链接: https://www.nowcoder.com/acm/contest/139/J 题意: 给出n个整数的序列a(1≤ai≤n)和q个询问(1≤n,q≤1e5),每个询问包含两个整数L和R( ...

  9. 牛客网多校训练第一场 I - Substring(后缀数组 + 重复处理)

    链接: https://www.nowcoder.com/acm/contest/139/I 题意: 给出一个n(1≤n≤5e4)个字符的字符串s(si ∈ {a,b,c}),求最多可以从n*(n+1 ...

随机推荐

  1. Codeforces Round #271 (Div. 2) E. Pillars 线段树优化dp

    E. Pillars time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  2. Intellij idea 2017 图标含义

    File Type Icon Recognized in ActionScript files ActionScript files Ultimate Edition Active Server Pa ...

  3. python网络编程基础之socket粘包现象

    粘包现象两种 登陆 #服务端import json import socket server=socket.socket()#创建socket对象 ip_port=('127.0.0.1',8001) ...

  4. django序列化 serializers

    Django的序列化工具让你可以将Django的模型‘翻译’成其它格式的数据.通常情况下,这种其它格式的数据是基于文本的,并且用于数据交换\传输过程. 一.序列化数据 Django为我们提供了一个强大 ...

  5. [osg]osg窗口显示和单屏幕显示

    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("cow.osg"); osg::ref_ptr&l ...

  6. eclipse中启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误

    原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者jdk并配置好环境变量.(2)copy一个jvm.dll放在该目录下. 原因2:eclipse的版本与jre或者jdk版本不一致 ...

  7. linux基础01-bash特性

    (1) ls -l:长格式文件类型: -:普通文件 (f) d: 目录文件 b: 块设备文件 (block) c: 字符设备文件 (character) l: 符号链接文件(symbolic link ...

  8. c++-pimer-plus-6th-chapter02

    <C++ primer plus 英文版 第六版>娓娓道来.这个是上下分册.而且,出版时间是最新的2015年,买回来发现网上的勘误基本都被纠正过来了,极个别错误没有影响到理解,好哎!而且发 ...

  9. canvas学习之柱状图

    项目地址:http://pan.baidu.com/s/1nvhWrwP 因为最近项目中使用到了图表,而且个人一直希望研究canvas,所以最近几天花时间对canvas好好研究了一下,并写了一个dem ...

  10. Confluence 6 设置一个空间主页

    当你创建一个空间的时候,Confluence 将会自动为你创建的空间新建一个主页.如果你的空间是从蓝图中创建,并且蓝图中已经有一个供使用的主页了,那么这个主页将会自动从蓝图中载入有用的宏和在蓝图中指定 ...