链接: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
#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< 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);
}
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章