Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4212    Accepted Submission(s): 1913 Problem Description CC always becomes very depressed at the end of this month, he has checked…
<题目链接> 题目大意: 给你一个字符串,要求将字符串的全部字符最少循环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] =…
//len-next[len]为最小循环节的长度 # include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int len; char a[100010]; int next[100010]; void Getnext() { int i=0,j=-1; next[0]=-1; while(i<=len) { if(j==-1||a[i]==a[j]) 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为循环节的长度…
题目地址: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…
题目链接:HDU 3746 Sample Input 3 aaa abca abcde Sample Output 0 2 5 Author possessor WC Source HDU 3rd "Vegetable-Birds Cup" Programming Open Contest Solution 题意 给定一个字符串,问至少需要在末尾添加多少个字符使得字符串循环. 思路 KMP 设前缀函数为 \(\pi()\),字符串长度为 \(n\),下标从 \(1\) 开始. 最小循环…
Cyclic Nacklace Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3746 Mean: 给你一个字符串,让你在后面加尽量少的字符,使得这个字符串成为一个重复串. 例: abca---添加bc,成为abcabc abcd---添加abcd,成为abcdabcd aa---无需添加 analyse: 经典的求最小循环节. 首先给出结论:一个字符串的最小循环节为:len-next[len]. 证明: 举个例子:abcab…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description CC always becomes very depressed at the end of this month, he has checked his credit card yesterd…
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11516    Accepted Submission(s): 4913 Problem Description CC always becomes very depressed at the end of this month, he has checke…
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14416    Accepted Submission(s): 6016 Problem Description CC always becomes very depressed at the end of this month, he has checke…
题意:给出一串字符串,可以在字符串的开头的结尾添加字符,求添加最少的字符,使这个字符串是循环的(例如:abcab 在结尾添加1个c变为 abcabc 既可). 思路:求出最小循环节,看总长能不能整除. #include<iostream> #include<stdio.h> #include<string.h> using namespace std; #define MaxSize 100005 int _next[MaxSize]; void GetNext(cha…
题意: 求最少需要在后面补几个字符能凑成两个循环. 分析: 最小循环节的应用,i-next[i]为最小循环节. #include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <strin…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087 题目大意:给你一个字符串,求出将字符串的最少出现两次循环节需要添加的字符数. 解题思路: 这题需要利用next数组的性质,求出字符串的最小循环节 有几个结论(具体可以看这里http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html): ①字符串长度为len,则len-next[len]为最小循环节. ②如果len%(len-nex…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 思路:KMP中Next数组的应用,求出最小的循环节,题目的意思是只能在字符串的后面上添加新的字符凑成两个循环节 用Next数组来求最小循环节的方法见这:http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html #include<string.h> #include<stdio.h> #include<iost…
题目链接: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…
串珠子 题目大意:给定一个字串,要你找到如果要使之成为循环串,在末尾需要的最小的字数(只能添加字符,不能删减字符) 首先联动一下之前做过的动态规划问题POJ 3280,当然了3280这一题是用的LD,因为他可以添加或者删除(加上修改也行,但是要改状态方程了) 而我们现在要讨论的这一题(HDU 3746)是有限制的,首先它只能添加不能删除,其次一定是要在末尾添加. 其实这样的题用kmp可以很快地解决,其实这样的题目是循环节的题目,之前我已经写过很多了,这一题是对循环节的深刻理解. 首先我们我们明白…
思路: 最小循环节的解释在这里,有人证明了那么就很好计算了 之前对KMP了解不是很深啊,就很容易做错,特别是对fail的理解 注意一下这里getFail的不同含义 代码: #include<iostream> #include<algorithm> const int N = 1000000+5; const int INF = 0x3f3f3f3f; using namespace std; int fail[N]; char p[N],t[N]; void getFail(){…
题意: 给一个字符串,问:要补多少个字符才能让其出现循环?出现循环是指循环节与字符串长度不相等.比如abc要补多个变成abcabc.若已经循环,输出0. 思路: 根据最小循环节的公式,当len%(len-next[len])==0时,最小循环节为len/(len-next[len]),而当len%(len-next[len])!=0时,就没有循环节.可以通过在串尾补上一些字符,使得len%(len-next[len])==0,就会出现循环节了. #include <bits/stdc++.h>…
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…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10685    Accepted Submission(s): 4583 Problem Description CC always becomes very depressed at the end of this month, he has checked his credit car…
http://acm.hdu.edu.cn/showproblem.php?pid=3746 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9975    Accepted Submission(s): 4267 Problem Description CC always becomes very depressed at the e…
题目请点我 题解: 题目大意:有一个字符串s.能够在前后加入字符,使字符串成为一个循环次数至少为2的循环字符串.输出最少须要加入的字符数目. 首先能够证明题目能够等价为仅仅在末尾加入字符使满足题意.要找到加入资格字符我们首先要找到循环单位的长度.利用一个辅助数组储存从起始位置開始长度为i的串的循环长度,初始值为i,利用与Next数组之间的关系来更新.找到循环长度.比方字符串abcabc,Next[i] = 3,cycle[3] = 3,有等价关系i-Next[i] = cycle[Next[i]…
http://acm.hdu.edu.cn/showproblem.php?pid=3746 Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4498    Accepted Submission(s): 2051 Problem Description CC always becomes very dep…
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2538    Accepted Submission(s): 1154 Problem Description CC always becomes very depressed at the end of this month, he has checke…
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…
CC这个月底总是很郁闷,昨天他查了他的信用卡,没有任何意外,只剩下99.9元了.他很苦恼,想着如何度过这最后的几天.受"HDU CakeMan"企业家精神的启发,他想卖一些小东西来赚钱.当然,这并非易事.圣诞节就要到了,男孩们都忙着挑选圣诞礼物送给女朋友.人们认为,链手镯是一个很好的选择.然而,事情并不总是那么简单,众所周知,女孩喜欢用五颜六色的装饰来使手镯显得生动活泼,同时她们也想展示自己作为大学生成熟的一面.CC了解了女孩们的需求后,打算出售这款名为CharmBracelet的ch…
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…
Cyclic Nacklace HDU 3746 KMP 循环节 题意 给你一个字符串,然后在字符串的末尾添加最少的字符,使这个字符串经过首尾链接后是一个由循环节构成的环. 解题思路 next[len]-len的差即是循环部分的长度. 这个是重点.这个题目自己开始没有想明白,看的博客,推荐这个. 代码实现 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const i…