HDU_3746 Cyclic Nacklace 【KMP的应用】】的更多相关文章

题目请点我 题解: 题目大意:有一个字符串s.能够在前后加入字符,使字符串成为一个循环次数至少为2的循环字符串.输出最少须要加入的字符数目. 首先能够证明题目能够等价为仅仅在末尾加入字符使满足题意.要找到加入资格字符我们首先要找到循环单位的长度.利用一个辅助数组储存从起始位置開始长度为i的串的循环长度,初始值为i,利用与Next数组之间的关系来更新.找到循环长度.比方字符串abcabc,Next[i] = 3,cycle[3] = 3,有等价关系i-Next[i] = cycle[Next[i]…
Cyclic Nacklace Problem Description CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, without any surprise, there are only 99.9 yuan left. he is too distressed and thinking about how to tide over the…
Cyclic Nacklace 题意:给一个长度为Len( 3 <= Len <= 100000 )的英文串,问你在字符串后面最少添加几个字符可以使得添加后的串为周期串? Sample Input 3 aaa abca abcde   Sample Output 0 2 5   思路:要是写过period再来写这道题会发现很简单:就是在getfail()得到f[]之后,贪心地看最后一个字符所能用到的最长后缀长度为多少?而这个后缀长度就是n - n%len;(n为字符串长度,len为循环节的长度…
题目链接:https://vjudge.net/problem/HDU-3746 Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10985    Accepted Submission(s): 4692 Problem Description CC always becomes very depresse…
一.题目 HDU3746 二.分析 KMP比较好解决的一个问题:如果求一个串中的循环节? 仔细回想KMP的用法,重点是next数组,相当于就是后缀和前缀的比较,那么不正是方便了我们确定循环节? 如果以字符串的最后一个位置(非字符)分析,那么这个位置的当前next值,就是我们串前缀和后缀的交集的最长值,所以只需要用长度Len去减去这个next值就可以得出循环节的长度了. 1 $Len\%(Len-next[Len]) \&\& Len != Len - next[Len]$ 此时,字符串已经…
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, without any surprise, there are only 99.9 yuan left. he is too distressed and thinking about how to tide over the last days. Being inspired by the en…
串珠子 题目大意:给定一个字串,要你找到如果要使之成为循环串,在末尾需要的最小的字数(只能添加字符,不能删减字符) 首先联动一下之前做过的动态规划问题POJ 3280,当然了3280这一题是用的LD,因为他可以添加或者删除(加上修改也行,但是要改状态方程了) 而我们现在要讨论的这一题(HDU 3746)是有限制的,首先它只能添加不能删除,其次一定是要在末尾添加. 其实这样的题用kmp可以很快地解决,其实这样的题目是循环节的题目,之前我已经写过很多了,这一题是对循环节的深刻理解. 首先我们我们明白…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3746 KMP算法—— AC代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <vector> #include <list&…
Problem Description CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, without any surprise, there are only 99.9 yuan left. he is too distressed and thinking about how to tide over the last days. Bein…
<题目链接> 题目大意: 给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数. [>>>kmp next函数 kmp的周期问题]  #include <cstdio> #include <cstring> + ; char s[maxn]; int Next[maxn]; void get_next() { , k = -; Next[] = -; while (s[j]) { || s[j] == s[k]) Next[++j] =…