?
| Time Limit: 1000MS | ? | Memory Limit: 65536K |
| Total Submissions: 7241 | ? | Accepted: 2162 |
?
Description
The repetition number of a string is defined as the maximum number R such that the string can be partitioned into R same consecutive substrings. For example, the repetition number of ababab is 3 and ababa is 1.
Given a string containing lowercase letters, you are to find a substring of it with maximum repetition number.
Input
The input consists of multiple test cases. Each test case contains exactly one line, which
gives a non-empty string consisting of lowercase letters. The length of the string will not be greater than 100,000.
The last test case is followed by a line containing a '#'.
Output
For each test case, print a line containing the test case number( beginning with 1) followed by the substring of maximum repetition number. If there are multiple substrings of maximum repetition number, print the lexicographically smallest one.
Sample Input
ccabababc daabbccaa #
Sample Output
Case 1: ababab Case 2: aa
Source
2008 Asia Hefei Regional Contest Online by USTC?
题意:求这个字符串内部循环重复次数最多的子串。输出字典序最小的。
思路:论文上的经典题。

就是先枚举长度L,表示长度为L的子串循环,肯定可以至少出现一次,出现两次以上枚举的时候肯定有s[i]==s[i+L],然后求这两个i和i+L后缀的最长公共前缀,记为k,那么至少出现了K/L+1,然后是是s[i]往前补够看能否多匹配一个。这样就得到了长度为L的子串最大循环次数。
对于求字典序最小的,我们枚举sa数组,判断sa[i],sa[i+L]后缀的最长公共前缀是否满足,遇到第一个满足就是字典序最小的。
?
/** * @author neko01 */ //#pragma comment(linker, /STACK:102400000,102400000) #include#include #include #include #include #include #include #include #include #include
?
?