链接: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. HDU 6249 Alice’s Stamps(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=6249 题意: 给出n个区间,求选k个区间的最大区间并. 思路: 可能存在左端点相同的多个区间,那么此时我们肯定选 ...

  2. 51nod 1349 最大值(单调栈)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1349 题意: 求区间内最大值大于等于k的区间个数. 思路: 利用求出对于 ...

  3. codeforces gym 100947 J. Killing everything dp+二分

    J. Killing everything time limit per test 4 seconds memory limit per test 64 megabytes input standar ...

  4. python 定时器

    2s启动一个定时器: import threading import time def hello(name): print "hello %s\n" % name global ...

  5. spring mvc 形参类型

    spring mvc 形参类型 1 没有占位符号的,形参的名字为参数的名称 请求路径为:organtrans/t1/t5?a=1(a为形参的的名称必须一致) @RequestMapping(" ...

  6. php中if(\$a==\$b)和if(\$a=\$b)什么区别?

    <?php // if($a==$b)和if($a=$b)什么区别? $a = 1; $b = 1; if ($a == $b) { // 通过 echo '通过'.PHP_EOL; } if ...

  7. java 之2D过气游戏类的写法

    2D游戏中各对象的父类 package cn.littlepage.game; import java.awt.Graphics; import java.awt.Image; import java ...

  8. Golang socket

    1.本例子实现了一个简单的TCP echo.客户端发送Hello,服务端回应World. 参考:<Socket编程> 2.服务端代码 package main import ( " ...

  9. eclipse中选中一个单词 其他相同的也被选中 怎么设置

    转自:https://zhidao.baidu.com/question/72621094.html 打开Window——Preferences 选择Java——Editor——Mark Occure ...

  10. nodejs实现文件的拷贝复制

    var fs = require( 'fs' ), stat = fs.stat; /* 05 * 复制目录中的所有文件包括子目录 06 * @param{ String } 需要复制的目录 07 * ...