博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
牛客网暑期ACM多校训练营(第三场) E-Sort String next数组的应用
阅读量:4540 次
发布时间:2019-06-08

本文共 1298 字,大约阅读时间需要 4 分钟。

链接:

来源:牛客网
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!

输入

abab

输出

22 0 22 1 3

题目大意: 给一个字符串,然后将字符串前i个字符移到组字符串的后面,组成新的字符串,如果有遇到相同的字符串分为一组,然后问有多少组,每组按字典序输出字符串的下标

例如 abab

i = 0 的时候,就是前0个字符串移到后面 也就是 abab
i =1 的时候 就是 baba
i=2 的时候 ,就是 abab
i=3的时候,就是 baba

所以有两组相同的,每组有两个数

 

通过next数组找到最小循环节, 如果 len % (len - next[len]) == 0 说明都是由最小循环节构成的。

#include 
#include
#include
using namespace std;const int maxn=1e6+10;int nexts[maxn];char str[maxn];void get_next(int len){ int i=0,j=-1; nexts[0]=-1; while(i

 

转载于:https://www.cnblogs.com/Fy1999/p/9383094.html

你可能感兴趣的文章
【Flex】读取本地XML,然后XML数据转成JSON数据
查看>>
字符串循环右移-c语言
查看>>
解决从pl/sql查看oracle的number(19)类型数据为科学计数法的有关问题
查看>>
古训《增广贤文》
查看>>
职场的真相——七句话
查看>>
xcode命令行编译时:codesign命令,抛出“User interaction is not allowed.”异常 的处理...
查看>>
[转载]开机出现A disk read error occurred错误
查看>>
STM32 C++编程 002 GPIO类
查看>>
ELK-Elasticsearch安装
查看>>
[Win8.1系统]双系统
查看>>
HDU 3899 树形DP
查看>>
获取当前页面url信息
查看>>
Java容器类源码分析前言之集合框架结构(基于JDK8)
查看>>
linux下C/C++程序的内存布局
查看>>
单词计数问题
查看>>
php 魔术方法 __autoload()
查看>>
js div拖动动画运行轨迹效果
查看>>
Recipe 1.9. Processing a String One Word at a Time
查看>>
Linux 下查看系统是32位 还是64 位的方法
查看>>
MySQL 引擎 和 InnoDB并发控制 简介
查看>>