POJ2752(KMP)
来源:互联网 发布:公司软件著作权转让 编辑:程序博客网 时间:2024/06/08 15:16
大意:给定一个字符串,求所有可能的既是前缀又是后缀的字串长度。
分析:按题目的意思很像求KMP中的next数组。next[len]是最大的前缀-后缀字符串长度,以此类推next[next[len]]同样为满足条件的前缀-后缀字符串长度。
代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;char str[400005];int len, next1[400005], ans[400005];void getnext(){int i = 0, j = -1;next1[0] = -1;while (i < len){if (j == -1 || str[i] == str[j]){i++;j++;next1[i] = j;}elsej = next1[j];}}int main(){while (scanf("%s", str) != EOF){len = strlen(str);getnext();ans[0] = len;int n = 0, i = len;while (next1[i] > 0){ans[++n] = next1[i];i = next1[i];}for (i = n; i >= 0; i--)printf("%d ",ans[i]);printf("\n");}return 0;}
0 0
- poj2752 kmp
- poj2752---KMP
- poj2752(KMP)
- poj2752 KMP
- POJ2752(KMP)
- poj2752 Milking Grid--------KMP
- poj2752 kmp 进一步运用
- 模式匹配KMP POJ2752
- KMP 专场 POJ2752
- poj2752 kmp 模板题
- poj2752 扩展kmp
- poj2752 KMP水题
- kmp练习poj2752
- POJ2752 字符串巩固题KMP
- poj2752 kmp 最短子串重复次数
- POJ2752【KMP-next数组含义】
- POJ2752 KMP next数组的活用
- POJ2752 KMP中next数组的应用
- Windows下多线程编程(一)
- java获取指定连接上的图片并保存到本地
- [python]4.7.2. Keyword Arguments
- 理解RESTful架构
- java实现通讯录Gui
- POJ2752(KMP)
- django框架从零开始_008_页面元素 表单处理
- MMU内存管理单元
- Spring AOP源码分析(生成代理对象)
- 八大排序之快排
- 6.类(1)--类的定义
- Java Web实用小知识01
- 64位plsql developer无法导入导出的解决
- 从JBoss Seam 2.x迁移到JavaEE 7之三:对象的注入