POJ 2752 Seek the Name, Seek the Fame kmp算法
来源:互联网 发布:js url转base64编码 编辑:程序博客网 时间:2024/06/05 10:37
题目:http://poj.org/problem?id=2752
题意:给定一个字符串,求这个字符串前缀等于后缀时的长度(前缀或后缀长度)
思路:用next数组性质可做,画个图很容易看出来
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 400010;char s[N];int nt[N];void getnt(){ int i = 0, j = -1; nt[0] = -1; while(s[i]) { if(j == -1 || s[i] == s[j]) i++, j++, nt[i] = j; else j = nt[j]; }}int main(){ while(~ scanf("%s", s)) { getnt(); int len = strlen(s); int ans[N], k = 0; while(len != 0) ans[k++] = len, len = nt[len]; for(int i = k - 1; i >= 0; i--) printf("%d%c", ans[i], i == 0 ? '\n' : ' '); } return 0;}
0 0
- poj 2752 Seek the Name, Seek the Fame KMP算法
- POJ 2752 Seek the Name, Seek the Fame kmp算法
- poj 2752 Seek the Name, Seek the Fame(KMP)
- poj 2752 Seek the Name, Seek the Fame---kmp
- POJ 2752 Seek the Name, Seek the Fame KMP
- [poj 2752] Seek the Name, Seek the Fame[KMP]
- poj 2752 Seek the Name, Seek the Fame (KMP)
- POJ 2752 Seek the Name, Seek the Fame (KMP)
- KMP poj 2752 Seek the Name, Seek the Fame
- POJ 2752 Seek the Name, Seek the Fame KMP
- poj 2752 Seek the Name, Seek the Fame(KMP)
- POJ 2752 Seek the Name, Seek the Fame(KMP)
- POJ 2752 Seek the Name, Seek the Fame / KMP
- poj 2752 Seek the Name, Seek the Fame(KMP)
- Seek the Name, Seek the Fame - POJ 2752 KMP
- poj 2752 Seek the Name, Seek the Fame KMP
- poj 2752 Seek the Name, Seek the Fame,KMP
- poj 2752 Seek the Name, Seek the Fame(数据结构:KMP)
- Android Service 服务的基本用法
- 三十天完成一个Android项目(Android应用程序的构成)
- Android最佳性能实践(四)——布局优化技巧
- DNS域名轮循业务监控
- CodeBlocks快捷键大全(附汉化教程及其文件)
- POJ 2752 Seek the Name, Seek the Fame kmp算法
- HDU1253 胜利大逃亡(BFS)
- MyBatis增删改查
- BZOJ 1087: [SCOI2005]互不侵犯King
- ruby on rails (MVC)
- 解决spring设置filter过滤器结合rest风格获取post请求body参数输入流问题
- android接收短信(SmsMessage.createFromPdu((byte[])obj)不推荐使用的处理方法)
- Oracle小白第一次折腾Oracle遇到的问题
- HDU1269 迷宫城堡