牛客第三场多校 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 ...
随机推荐
- 20170706xlVBA汇总历时对阵数据
Public Sub GatherFilesData() Application.ScreenUpdating = False Application.DisplayAlerts = False Ap ...
- 模拟spring的IoC
1.新建一个web项目,jdk版本为1.8.0_111,使用 Jsp + Servlet + Model 实现MVC模式,并使用BeanFactory工厂 + xml配置文件 + 反射 来解耦合 整个 ...
- git merge和git rebase的区别
git merge是用来合并两个分支的.# 将b分支合并到当前分支git merge b git cherry-pick可以选择某一个分支中的一个或几个commit(s)来进行操作.例如,假设我 们有 ...
- acl使用示例
declare v_count number; uprinciple varchar2(20); principle varchar2(20); begin uprinciple := ...
- oracle坏块处理记录
1. 执行sql:select count(distinct id) from bw_fpzxx ,报错如下: ORA-01578: ORACLE 数据块损坏 (文件号 16, 块号 195428)O ...
- Leetcode 993. 二叉树的堂兄弟节点
993. 二叉树的堂兄弟节点 显示英文描述 我的提交返回竞赛 用户通过次数195 用户尝试次数229 通过次数195 提交次数462 题目难度Easy 在二叉树中,根节点位于深度 0 处,每个深 ...
- 【Linux】shell学习之sed
sed替换命令 使用该命令,可以将特定字符串或匹配的规则表达式用另一个字符串替换. sed 's/88/--/' filename 将filename每行第一次出现的88用字符串--替换,然后将该文件 ...
- 二十二、Spring MVC与Structs2的区别总结
一.框架的入口 1.Structs2采用Filter(StructsPrepartAndExecuteFilter)来进行实现. 2.SpringMVC采用Servlet(DispatcherServ ...
- Qt Widgets——抽象按钮及其继承类
QAbstractButton是有关“按钮”的基类 描述了一个按钮应该具有的组成.它的公有函数如下: QAbstractButton(QWidget * parent = ) ~QAbstractBu ...
- Struts初步入门(四)
1.默认Action-深入Struts struts.xml 文件: <struts> <package name="default" namespace=&qu ...