poj 2406 Power Strings(连续重复子串)
来源:互联网 发布:python中对数函数 编辑:程序博客网 时间:2024/05/22 14:12
Power Strings
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 33469 Accepted: 13902
Description
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).
Input
Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
Output
For each s you should print the largest n such that s = a^n for some string a.
Sample Input
abcdaaaaababab.
Sample Output
143
Hint
This problem has huge input, use scanf instead of cin to avoid time limit exceed.
题意:给定一个字符串L,已知这个字符串是由某个字符串S 重复R 次而得到的,
求R 的最大值。
思路:穷举字符串S 的长度k,然后判断是否满足。判断的时候,先看字符串L 的长度能否被k 整除,再看suffix(1)和suffix(k+1)的最长公共前缀是否等于n-k。在询问最长公共前缀的时候,suffix(1)是固定的,所以RMQ问题没有必要做所有的预处理, 只需求出height 数组中的每一个数到height[rank[1]]之间的最小值即可。整个做法的时间复杂度为O(n)。
求R 的最大值。
思路:穷举字符串S 的长度k,然后判断是否满足。判断的时候,先看字符串L 的长度能否被k 整除,再看suffix(1)和suffix(k+1)的最长公共前缀是否等于n-k。在询问最长公共前缀的时候,suffix(1)是固定的,所以RMQ问题没有必要做所有的预处理, 只需求出height 数组中的每一个数到height[rank[1]]之间的最小值即可。整个做法的时间复杂度为O(n)。
0 0
- poj 2406 Power Strings(连续重复子串)
- POJ 2406 Power Strings(后缀数组[连续重复子串])
- poj 2406 Power Strings 【KMP求最小循环节】【后缀数组求连续重复子串】
- POJ 2406 Power Strings 求连续重复字串(kmp)
- 【kmp】【后缀数组】【连续重复子串】Power Strings POJ2406
- POJ 2406 Power Strings ( 后缀数组 连续重复字串 )
- POJ 2406 Power Strings(KMP求一个串的重复子串)
- POJ 2406-Power Strings(重复子串-KMP中的next数组)
- POJ-2406 Power Strings(KMP求重复子串出现的最大次数)
- POJ 2406(连续重复子串)
- poj 2406 Power Strings (最小重复子串出现次数 kmp)
- POJ 2046 Power Strings(连续重复串重复次数--后缀数组)
- Power Strings(kmp 重复子串)
- poj2406 Power Strings(最大重复子串)
- poj 2406 "Power Strings"
- poj 2406 Power Strings
- POJ-2406 Power Strings
- POJ 2406 Power Strings
- UISearchbar的相关属性,方法的介绍
- java中equal和==的比较
- 高德地图教程_通过关键字进行导航
- Java集合
- linux下开无线网络
- poj 2406 Power Strings(连续重复子串)
- [Hb-I] 查看CPU和内存 用汇编指令编程
- 参数传递,修改
- 类似hibernate框架的mybatis框架学习总结
- 我的E9嵌入式之旅(一)
- Android获取网络状态
- JPA的一些坑
- 线性链表 java实现
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions