牛客第三场多校 E Sort String
链接:https://www.nowcoder.com/acm/contest/141/E
来源:牛客网
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
-->
输入
abab
输出
2
2 0 2
2 1 3
输入
deadbeef
输出
8
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7 题意:就是说把一个字符串分别再每一个位置,把前缀放到后缀后面组成新的字符串,然后把相同字符串分入一个组,组里面的字符串索引按字典序排序
例如实例一
abcb在每个位置分别组成 abab+""=abab
bab+"a"=baba
ab+"ab"=abab
b+"aba"=baba
由此我们可以看出(0,2)(1,3)分别组成一组 然后我们可以仔细想想,只要字符串有一个字符不构成循环就会变成每个位置各在一组
例如 ababac
ababac+""=ababac
babac+"a"=babaca
abac+"ab"=abacab
bac+"aba"=bacaba
ac+"abab"=acabab
c+"ababa"=cababa
没有一个相同 我们就会发现只有构成了字符循环才会有可能有多个字符串分在同一个组,而且还是有规律的,
如abcabc abc为最小循环节,三个一循环,那么我们的组就有三个组,两个循环,说明一个组里面有两个成员,这个自己写几个例子就会明白
然后我连最小循环节都说出来了,相信大家也明白了,使用kmp求next数组求出循环节
#include<cstdio>
#include<cstring>
using namespace std;
int len;
int next[];
char s[];
int getnext(char s[])//求出next数组
{ int i=,j=-;
next[]=-;
while(i<len)
{
if(j==-||s[i]==s[j])
{
next[++i]=++j;
}
else j=next[j];
}
return next[len];
}
int main()
{
int n;
scanf("%s",s);
len=strlen(s);
int m=len-getnext(s);//循环节的长度
if(len==m)
{
printf("%d\n",len);
for(int i=;i<len;i++)
{
printf("1 %d\n",i);
}
}
else
{ if(len%m==)//判断是否构成了循环
{
printf("%d\n",m);
for(int i=;i<m;i++)
{
printf("%d",len/m);
for(int j=i;j<len;j+=m)
{
printf(" %d",j);
}
printf("\n");
}
}
else {
printf("%d\n",len);
for(int i=;i<len;i++)
{
printf("1 %d\n",i);
}
}
}
}
牛客第三场多校 E Sort String的更多相关文章
- 牛客第三场多校 H Diff-prime Pairs
链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calcul ...
- PACM Team(牛客第三场多校赛+dp+卡内存+打印路径)
题目链接(貌似未报名的不能进去):https://www.nowcoder.com/acm/contest/141/A 题目: 题意:背包题意,并打印路径. 思路:正常背包思路,不过五维的dp很容易爆 ...
- uestc summer training #9 牛客第三场 BFS计数
G.coloring tree BFS计数 题目:给你n(<=5000)个节点的一颗树 你有K(<=5000)种颜色 你可以给每一个节点染一种颜色 总共有Kn种染色方法 在一种染色方法中 ...
- 牛客第五场多校 J plan 思维
链接:https://www.nowcoder.com/acm/contest/143/J来源:牛客网 There are n students going to travel. And hotel ...
- 2019牛客第八场多校 E_Explorer 可撤销并查集(栈)+线段树
目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)E_Explorer) 题意: 链接 题目类似:CF366D,Gym101652T 本题给你\(n(100000)\)个点\(m(1000 ...
- 牛客第五场多校 A gpa 分数规划(模板)
链接:https://www.nowcoder.com/acm/contest/143/A来源:牛客网 Kanade selected n courses in the university. The ...
- Shuffle Cards(牛客第三场+splay)
题目: 题意:将1~n的数进行m次操作,每次操作将第pi位到pi+si-1位的数字移到第一位,求最后的排列. 思路:现在还没不会写splay,在知道这是splay模板题后找了一波别人的模板,虽然过了, ...
- 牛客第三场 J LRU management
起初看到这道题的时候,草草就放过去了,开了另一道题,结果开题不顺利,总是感觉差一点就可以做出来,以至于一直到最后都没能看这道题qaq 题意:类似于操作系统上讲的LRU算法,有两个操作,0操作代表访问其 ...
- 最长相同01数的子串(map搞搞)--牛客第三场 -- Crazy Binary String
题意: 如题. 或者用我的数组分治也可以,就是有点愚蠢. //#include <bits/stdc++.h> #include <map> #include <iost ...
随机推荐
- LeetCode--232--用栈实现队列
问题描述: 使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部. pop() -- 从队列首部移除元素. peek() -- 返回队列首部的元素. empty() -- 返回队 ...
- 20170928xlVBA自定义分类汇总
SubtotalByCQL Range("A1:E100").Value, "Select 1,2,Sum(4),Count(4) GroupBy 1,2", ...
- ActionCable的部署(参考Gorails)
Gorails视频 https://gorails.com/deploy/actioncable Action Cable – Integrated WebSockets for Rails http ...
- Two Melodies CodeForces - 813D (DP,技巧)
https://codeforces.com/problemset/problem/813/D dp[i][j] = 一条链以i结尾, 另一条链以j结尾的最大值 关键要保证转移时两条链不能相交 #in ...
- 『TensorFlow Internals』笔记_源码结构
零.资料集合 知乎专栏:Bob学步 知乎提问:如何高效的学习 TensorFlow 代码?. 大佬刘光聪(Github,简书) 开源书:TensorFlow Internals,强烈推荐(本博客参考书 ...
- bzoj2300#2300. [HAOI2011]防线修建
题解:带删点的维护凸包,1.删点2.查询凸包周长 题解:倒着做就成了带加点的维护凸包,加点时维护一下周长就没了 //#pragma GCC optimize(2) //#pragma GCC opti ...
- bootstrap fileinput组件的使用
组件的下载地址为:https://github.com/kartik-v/bootstrap-fileinput 比较详细的介绍可参看:http://www.jq22.com/jquery-info5 ...
- SQLServer清空表
TRUNCATE TABLE TABLE_NAME 这个不记日志. delete table table_name 这个记日志 drop table table_name 删除表 TRUNCATE 语 ...
- 2017-3-31/socket
1. 讲讲你对套接字编程的理解,它的协议是如何的? socket通常称为"套接字",用于描述IP地址和端口,是一个通信链的句柄.应用程序通过套接字向网络发出请求或应答网络请求. 服 ...
- ThinkPHP3自动加载公共函数文件
7d 根目录 ├─Application 应用目录 │ ├─Common 公共模块 │ │ ├─Common 公共函数文件目录 │ │ │ ├─index.html │ │ ├─Config 配置文件 ...