POJ 2752 Seek the Name, Seek the Fame
2015-08-17 22:04
441 查看
题目链接:
http://poj.org/problem?id=2752
解题思路:
给你一个字符串s,从小到大输出s中既是前缀又是后缀的子串的长度。
利用next数组的存储的性质,即可得出正确的答案。。。
AC代码:
http://poj.org/problem?id=2752
解题思路:
给你一个字符串s,从小到大输出s中既是前缀又是后缀的子串的长度。
利用next数组的存储的性质,即可得出正确的答案。。。
AC代码:
#include <iostream> #include <cstdio> #include <string> #include <cstring> using namespace std; const int N = 400005; int Next ,ans ; char s ; void getnext(){ int j = 0,k = -1; int l = strlen(s); Next[0] = -1; while(j < l){ if(k == -1 || s[j] == s[k]){ j++;k++; Next[j] = k; } else k = Next[k]; } } void kmp(){ getnext(); int l = strlen(s); int i = l,sum = 0; while(i != 0){ ans[sum++] = Next[i]; i = Next[i]; } for(i = sum-2; i >= 0; i--) printf("%d ",ans[i]); printf("%d\n",l); } int main(){ while(~scanf("%s",s)){ kmp(); } return 0; }
相关文章推荐
- 关于System.Convert那些事
- 【Unity3D Game develop by example】简单的例子—平板接掉落球
- leetcode-110:判断平衡二叉树 Java
- POJ 3764 The xor-longest Path(字典树 + 贪心)
- Kruskal算法-图由邻接表实现
- 编辑距离计算-动态规划法
- 在Unity项目中使用渐进网格技术
- NS3网络仿真(12): ICMPv4协议
- java中String的常用方法
- Shell脚本学习笔记
- hdu(1069)——Monkey and Banana(LIS变形)
- POJ 3080--Blue Jeans【KMP && 暴力枚举】
- 每日五题(mybatis)
- Linux 网卡驱动学习(七)(MAC 与 IP)
- hdu1010Tempter of the Bone(dfs+奇偶剪枝)
- [笔记][Java7并发编程实战手册]3.3 资源的多副本并发访问控制Semaphore
- HDU 3790 最短路径问题【最短路 dijkstra 双权值】
- php使用curl post 乱码 淘宝手机 curl 注意事项 cookie无法传递
- Redis与SpringMVC整合
- 继承中的构造方法