牛客网多校第3场Esort string (kmp)
链接: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)的更多相关文章
- 牛客网多校第3场C-shuffle card 平衡树或stl(rope)
链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...
- 牛客网多校赛第九场A-circulant matrix【数论】
链接:https://www.nowcoder.com/acm/contest/147/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客网多校训练第二场D Kth Minimum Clique
链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...
- 牛客网多校第5场 H subseq 【树状数组+离散化】
题目:戳这里 学习博客:戳这里 题意:给n个数为a1~an,找到字典序第k小的序列,输出该序列所有数所在位置. 解题思路:先把所有序列预处理出来,方法是设一个数组为dp,dp[i]表示以i为开头的序列 ...
- 牛客网多校第5场 I vcd 【树状数组+离散化处理】【非原创】
题目:戳这里 学习博客:戳这里 作者:阿狸是狐狸啦 n个点,一个点集S是好的,当且仅当对于他的每个子集T,存在一个右边无限延长的矩形,使的这个矩形包含了T,但是和S-T没有交集. 求有多少个这种集合. ...
- 牛客网多校第4场 J Hash Function 【思维+并查集建边】
题目链接:戳这里 学习博客:戳这里 题意: 有n个空位,给一个数x,如果x%n位数空的,就把x放上去,如果不是空的,就看(x+1)%n是不是空的. 现在给一个已经放过数的状态,求放数字的顺序.(要求字 ...
- 牛客网多校第4场 A.Ternary String 【欧拉降幂】
题目:戳这里 学习博客:戳这里 欧拉函数的性质: ① N是不为0的整数.φ(1)=1(唯一和1互质的数就是1本身) ② 除了N=2,φ(N)都是偶数. ③ 小于N且与N互质的所有数的和是φ(n)*n/ ...
- 牛客网多校训练第一场 J - Different Integers(树状数组 + 问题转换)
链接: https://www.nowcoder.com/acm/contest/139/J 题意: 给出n个整数的序列a(1≤ai≤n)和q个询问(1≤n,q≤1e5),每个询问包含两个整数L和R( ...
- 牛客网多校训练第一场 I - Substring(后缀数组 + 重复处理)
链接: https://www.nowcoder.com/acm/contest/139/I 题意: 给出一个n(1≤n≤5e4)个字符的字符串s(si ∈ {a,b,c}),求最多可以从n*(n+1 ...
随机推荐
- 那些年我们一起用过的 PHP 函数(一)
用这个帖子记录一下 PHP 中比较常用的函数以及使用过程中需要注意的点,此贴持续更新 1.strpos() 函数 首先,我们知道 strpos() 函数是用于查找一个字符串在另一个字符串第一次 ...
- P1948 [USACO08JAN]电话线Telephone Lines
传送门 思路: 二分+最短路径:可以将长度小于等于 mid 的边视为长度为 0 的边,大于 mid 的边视为长度为 1 的边,最后用 dijkstra 检查 d [ n ] 是否小于等于 k 即可. ...
- go 接口以及对象的使用
// Sample program to show how to declare methods and how the Go // compiler supports them. package m ...
- 前端阶段_html部分
HTML 1.html5的第一行一定是<!DOCTYPE html>,h4太长,而且一般ide中会自动加载,了解即可. 2.h5的整个页面被<html></html> ...
- java四种访问权限符
(PS:其中private和protected不能修饰一般的类,否则编译就会报“modifier private not allowed here”,如果是内部类就另当别论了)
- 串口.Qt532测试(异步)
环境:Win7x64.Qt5.3.2 MSVC OpenGL(x86).vs2010(x86) 项目所在位置:E:\Project_Qt532\SeriesPort_Qt532_Z ZC:这里 同步方 ...
- eclipse打开失败
以前eclipse运行好好的,某一次运行启动不了,一直图标那里转圈,不能启动, 运行eclipsec.exe后,查看发现出现以下错误 SLF4J: Class path contains multip ...
- Eclipse+maven 构建第一个简单的springmvc项目
先给出项目的目录: 在eclipse下使用maven构建第一个springmvc项目步骤如下: 1.创建maven project(此处默认你已了解maven),此处需要注意以下两点 2.创建完毕后会 ...
- 力扣(LeetCode)67. 二进制求和
给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. 示例 1: 输入: a = "11", b = "1" 输出: ...
- 关于JavaScript和Java的区别和联系
转载自: Javascript和Java除了名字和语法有点像,其他没有任何的关系. 做个比较是为了让大家更好的理解Javascript,事实上,两种语言根本没有可比性,是完全不同的. Javasc ...