链接: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 ;
}

最新文章

  1. C语言中do...while(0)的妙用(转载)
  2. java.sql.SQLSyntaxErrorException: ORA-00936: 缺失表达式。
  3. 转:在支持ARC工程中编译不支持ARC的文件
  4. Python条件语句
  5. 读取本地Json文件
  6. Windows Server 2008 下ASP程序连接ORACLE数据库驱动错误
  7. 在Struts2中配置Action
  8. git冲突的发生和解决/git workspace关于git的配置
  9. Linux diff patch
  10. Oracle 视图添加主键
  11. CCCardinalSplineBy概念
  12. mac bash_profile
  13. 为什么内存使用2G的苹果手机比内存使用4G的安卓机更流畅?
  14. bzoj4896 补退选
  15. C++重载输入流复习
  16. pipe size设置
  17. java23种设计模式之: 策略模式,观察者模式
  18. Linux下安装配置virtualenv与virtualenvwrapper
  19. SpringMVC 拦截器HandlerInterceptor(一)
  20. BZOJ 4499: 线性函数

热门文章

  1. python学习 day013打卡 内置函数
  2. web开发测试注意点
  3. Jmeter工具
  4. Python深入:Distutils发布Python模块--转载
  5. Mysql 函数使用记录(三)——UNIX_TIMESTAMP() 、UNIX_TIMESTAMP(date)
  6. [转]QT中QString与string的转化,解决中文乱码问题
  7. kubernetes 简介:kube-dns 和服务发现
  8. 《剑指offer》第四十一题(数据流中的中位数)
  9. AtCoder Grand Contest 025 B - RGB Coloring
  10. tchart5