![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
字符串
文章平均质量分 52
omsobliga
这个作者很懒,什么都没留下…
展开
-
644 - Immediate Decodability未通过
//未通过!#include #include char codes[10][15];int n;int check(int j){ for(int i=j+1;i<n;i++) { int k; for(k=0;codes[i][k] && codes[j][k]==codes[i][k];k++); if(codes[i][k]=='\0') retur原创 2012-01-12 23:36:58 · 327 阅读 · 0 评论 -
HDU 1711 Number Sequence(KMP)
/*最基础的KMP算法题,只是把字符改为了数字*/#include const int mMax = 10007;const int nMax = 1000007;int N, M;int a[nMax],b[mMax];int next[mMax];void init(){ scanf("%d %d", &N, &M); int i; for(i = 0; i < N;原创 2012-05-15 11:12:37 · 432 阅读 · 0 评论 -
HDU 3374 String Problem(最小表示法 + KMP求周期)
/*题意:环状字符串,输出最小表示数和最大表示数,和出现的次数题解:最小表示法 + KMP利用最小表示法求出最小表示数和最大表示数然后利用KMP求出字符串的最小循环节*/#include using namespace std;const int nMax = 1000010;char S[nMax];int next[nMax];int solve1(int len原创 2012-08-08 11:08:42 · 727 阅读 · 0 评论 -
POJ 1743 Musical Theme(后缀数组,最长重复子串)
/*题意:用数字代表音节,寻找最长主旋律,要求:不少于五个数字,不能重复;并不要求两段子串完全相同,相加同一个数字后相同也可以题解:我原来把字符串相加一个数字后做了一次拼接,结果超时。其实这道题,更好的解法是,另建一个数组存储前后数据之差,这样如果,存在主旋律,则这段字符串必然相等。然后问题就可以解决了。不过需要注意,最后结果需要加1这道题做了很久,最后AC,收获很大,①到④是曾经出现原创 2012-08-20 22:29:48 · 589 阅读 · 0 评论 -
A new common sub-strings problem(后缀数组,求第K小公共子串)
A new common sub-strings problemTime Limit:1000MS Memory Limit:65536KTotal Submit:7 Accepted:2Description一个字符串中一段连续的若干个字符称作这个字符串的“子串”,如果一个字符串同时是另外两个字符串的子串,就称这个字符串是另外两个字符串的“公共子串”。 现在GBQC国的原创 2012-08-22 19:06:32 · 1616 阅读 · 0 评论 -
后缀数组小结
初学后缀数组://后缀数组模板int wa[maxn],wb[maxn],wv[maxn],ws[maxn];//这些都是需要用到的中间变量int cmp(int *r,int a,int b,int l){ return r[a]==r[b]&&r[a+l]==r[b+l];}void da(int *r,int *sa,int n,int m)//这里的n应该是字符串长原创 2012-08-11 16:29:27 · 632 阅读 · 0 评论 -
HDU 3746 Cyclic Nacklace(KMP求最小循环元)
/*题意:组成一个环,要求至少包含两个相同字符串,求至少向给出字符串后面添加的字符数题解:根据KMP求出循环元,最小循环元t = len - next[len]。然后问题就很容易解决了。做完这道题,感触更深一些了,这个公式对任何字符串都适用。*/#include using namespace std;const int nMax = 100010;int T;char s[原创 2012-08-23 22:16:43 · 2134 阅读 · 1 评论 -
KMP(单模式匹配)
KMP处理问题:①单字符串匹配,返回匹配地址、求出匹配总次数②求循环元,t = len - next[len]简单心得:①next[]数组的有效范围是[0,len],len的时候,next[]为有效值②只需要记住next[0] = -1,next[1] = 0,这两个条件就可以写出求next[]的函数③匹配过程只需要O(N),所以i的值不需要回归。这里曾经纠结很久,matc原创 2012-04-09 15:14:44 · 530 阅读 · 0 评论 -
AC自动机(多模式匹配)
AC自动机主要解决的问题:多模式匹配(KMP则属于单模式匹配),n个单词在m个字符的文章中,出现过多少次。主要分三步:构建trie树、构建失败指针、寻找匹配个数Trie树:又称字典树、单词查找树,是一种树形结构,用于保存大量的字符串。它的优点是:利用字符串的公共前缀来节约存储空间。具体参见:http://www.cppblog.com/abilitytao/archive/2009原创 2012-08-02 19:43:39 · 790 阅读 · 0 评论 -
HDU 1358 Period(KMP求周期)
/*题意:输入字符串长度N和字符串S,要求输出所有字符串S前k个字母组成的序列A为循环序列时,循环序列的个数Ak,k从小到大一次输出。KMP解决,可以将算法时间复杂度缩小为O(N),然后找规律即可。KMP算法可将字符串匹配算法时间复杂度从O(N*M)缩小到O(N+M)*/#include const int nMax = 1000007;char S[nMax];int ne原创 2012-05-15 10:22:57 · 989 阅读 · 0 评论 -
hdU 2222 Keywords Search(AC自动机)
/*ACAC自动机问题参考:http://www.cppblog.com/mythit/archive/2009/04/21/80633.html*/#include using namespace std;const int nMax = 1000100;const int mMax = 60;const int Max = 26;struct Node{ Node原创 2012-05-15 09:08:42 · 453 阅读 · 0 评论 -
10115 - Automatic Editing未通过
//未通过!#include #include int main(){ char rules[2][15][85],edit[260],output[260]; int n; while(scanf("%d",&n) && n!=0) { getchar(); for(int i=0;i<n;i++) { gets(rules[0][i]); gets(r原创 2012-01-12 23:33:05 · 469 阅读 · 0 评论 -
10815 - Andy's First Dictionary未通过
收获:set做存储结构(平衡二叉树),需要调用#include set::iterator,insert;//程序有问题!//思路:折半查找,插入//收获:set做存储结构(平衡二叉树),set::iterator,insert;//string::empty(),string重定义后的+号运算#include #include #inclu原创 2012-01-12 23:42:33 · 357 阅读 · 0 评论 -
409 - Excuses, Excuses!未通过
//存在一个错误,使用一个外循环和使用嵌套循环,存在异常//gets()得到一串含空格的字符串#include #include #include /*int Match(char os[],char ot[]){ int len1=strlen(os),len2=strlen(ot);//注意不要搞混strlen() 和 sizeof() char s[25],t[75];原创 2012-01-12 23:50:11 · 475 阅读 · 0 评论 -
10361 - Automatic Poetry
//疑点解惑:首先重复定义i并不引起错误!,仅仅在vc6.0中发生的问题/*#include #include #define MAX 105int main(){ char l1[MAX],l2[MAX],c1[MAX],c2[MAX]; char s1[MAX],s2[MAX],s3[MAX],s4[MAX],s5[MAX],s[MAX]; int len1,len2,len原创 2012-01-12 23:54:10 · 452 阅读 · 0 评论 -
10878 - Decode the tape
#include #include int main(){ //freopen("data.in","r",stdin); //freopen("data.out","w",stdout); char ch[1000]; gets(ch); while(gets(ch)&&strcmp(ch,"___________")) { int len=strlen(ch); ch原创 2012-01-12 23:44:50 · 412 阅读 · 0 评论 -
537 - Artificial Intelligence未通过
//未通过,重点掌握:istringstream的用法。//整形和getline()或者(fgets())结合使用时要用getchar()来做区别/*#include #include #include #include #define MAX 105int main(){ struct { char Concept; char Prefix; double dat原创 2012-01-12 23:52:48 · 1146 阅读 · 0 评论 -
HDOJ 4162 Shape Number(最小表示法 )
/*题意:输入一个字符串,首先进行转换,对应位置变为该位置逆时针到下一个位置需要的变化次数,如果是最后一个则下一个位置为第一个。s[i] = s[i + 1] - s[i];如果s[i]为负,则加上8最小表示法*/#include using namespace std;const int nMax = 300010;char s[nMax];int ans[nMax];原创 2012-08-08 16:19:34 · 476 阅读 · 0 评论 -
POJ 2774 Long Long Message(后缀数组)
/*题意:输出两个字符串最大公共子串题解:将两个字符串对接,中间使用一个从未出现过的字符相连,然后问题就可以使用后缀数组解决*/#include using namespace std;const int nMax = 1000000;const int mMax = 0x7fff;char str[nMax];int num[nMax];int wa[nMax], wb[原创 2012-08-15 23:15:02 · 597 阅读 · 0 评论 -
POJ 3461 Oulipo(KMP求匹配次数)
/*题意:求某一单词在句子中出现的次数。做这道题的时候,匹配算法搞了很久,最后终于想明白了,受传统模式匹配算法的影响,认为①处也需要对i做一次变化。*/#include #include #include using namespace std;const int wMax = 10010;const int tMax = 1000010;char s[wMax], ss[原创 2012-08-23 22:22:22 · 661 阅读 · 0 评论