![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
串处理
文章平均质量分 70
代金桥
交流邮箱daijinqiao(at)163.com
展开
-
poj 3461 Oulipo
类型:KMP 题目:给定原串和模式串,求模式串在原串出现的次数 !!!char[]类型从1开始用scanf("%s %s", sp + 1, st + 1); // poj 3461 // wa ac 1264K 94MS #include #include #include #include using namespace std; #define FOR(i,a,b) for(原创 2012-03-08 21:12:22 · 175 阅读 · 0 评论 -
zoj 3587 Marlon's String
类型:KMP【经典】 题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4629 来源: ZOJ 10th Anniversary Contest 思路:以S串为原串,T串为模式串,做两次KMP运算,分别求出在原串中以长度为i的前缀和后缀的数量 !!!如果前缀串中包含部分前缀,需要对其累加 如:S = a a a原创 2012-03-19 13:34:38 · 456 阅读 · 0 评论 -
poj 2001 Shortest Prefixes
类型:Trie 题目:http://poj.org/problem?id=2001 来源:Rocky Mountain 2004 思路:对输入的字符串插入到字典树中,然后对每个字符串查找 结束条件:(1)当前字符只有一个分支(2)查到单词最后一个字符 // poj 2001 Shortest Prefixes // ac 472K 0MS #include #include #inc原创 2012-04-04 15:42:26 · 255 阅读 · 0 评论 -
poj 3450 Corporate Identity
类型:KMP 题目:给定n个字符串,求最长的公共子串,如果不唯一,输出字典序最小的串 思路:以第一个串的子串为模式串,从大到小枚举串的长度,依次和其他串匹配,如果都匹配成功,将该长度下字典序最小的子串输出 // poj 3450 Corporate Identity // tle tle ac 332K 1032MS #include #include #include #includ原创 2012-03-15 11:28:17 · 216 阅读 · 0 评论 -
ural 1684 Jack's Last Word
类型:KMP 题目:http://acm.timus.ru/problem.aspx?space=1&num=1684 思路:将amusing word看做模式串,将Jack's last word看做原串,进行匹配 在kmp算法中如果更新到第一个字符都不匹配即可结束,输出"yes" 如果为"no",保存字符的匹配位置,从后往前更新每个前缀串到第一个字符 如: abracadabra原创 2012-03-13 20:02:11 · 433 阅读 · 0 评论 -
uva 12012 Detection of Extraterrestrial
类型:KMP[经典] 题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3163 思路:枚举前缀,不断更新当前max值 字符串为周期串的条件是n % (n - next[n]) = 0 子串个数x为1时特殊考虑 数据: aba 答案:3 0原创 2012-03-09 22:44:21 · 350 阅读 · 0 评论 -
poj 2752 Seek the Name, Seek the Fame
类型:KMP 来源:POJ Monthly--2006.01.22,Zeyuan Zhu 题目:给定一个串,求其所有的即是其前缀又是其后缀的串的长度,从小到大输出 串本身即是其前缀又是其后缀,然后就是next[len]了,依次进行直到next[i] = 0 // poj 2752 // ac 2556K 157MS #include #include #include #incl原创 2012-03-09 08:09:04 · 196 阅读 · 0 评论 -
poj 2406 Power Strings
类型:KMP 题目:给定一个串,求该串的周期数 用next数组记录各个位置的next值 !!!串ababa // poj 2406 // wa wa ac 5128K 157MS #include #include #include #include using namespace std; #define FOR(i,a,b) for(i = (a); i < (b); ++i原创 2012-03-08 22:15:40 · 152 阅读 · 0 评论 -
hdoj 3746 Cyclic Nacklace
类型:KMP 题目:http://acm.hdu.edu.cn/showproblem.php?pid=3746 来源:HDU 3rd “Vegetable-Birds Cup” Programming Open Contest 思路: (1)字符加在前后等价 (2)注意非周期串的特殊情况:ababa // hdoj 3746 Cyclic Nacklace // ac 125MS原创 2012-04-15 08:57:26 · 304 阅读 · 0 评论