POJ 2752 Seek the Name, Seek the Fame
来源:互联网 发布:任我行 联通网络 编辑:程序博客网 时间:2024/04/28 05:43
KMP第二题,如果对KMP理解了的话,这道题应该想一下就能想出来
#include<stdio.h>#include<algorithm>using namespace std;char s[400005];int next[400005];int a[400005];//next数组范围为1-n,next[0]是不使用的void get_next(int n){ if(n==0) return; int i,j; j=next[0]=-1; i=0; while(i<n){ while(j!=-1 && s[j]!=s[i]) j=next[j]; next[++i]=++j; } int len=0; for(int i=next[n];i!=0;i=next[i]) a[len++]=i; for(int i=len-1;i>=0;i--) { printf("%d ",a[i]); } //if(next[n]!=0) printf("%d ",next[n]);}int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE int cas=0; while(scanf("%s",s)!=EOF){ int len=0; while(s[len]!='\0') len++; get_next(len); printf("%d\n",len); } return 0;}
0 0
- poj seek the name,seek the fame
- poj---Seek the Name, Seek the Fame
- Seek the Name, Seek the Fame POJ
- Seek the Name, Seek the Fame POJ
- POJ-2752 Seek the Name, Seek the Fame
- 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 (next)
- POJ:2752Seek the Name, Seek the Fame
- POJ 2752 - Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- POJ-2752-Seek the Name, Seek the Fame
- POJ 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- POJ 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame---kmp
- POJ 1961 Period
- 使用node更新google hosts
- 阿里面试总结
- 关于多态的讨论
- 安卓学习笔记(三)、使用Intent传递数据
- POJ 2752 Seek the Name, Seek the Fame
- 初识云计算的三种服务模式 (IaaS SaaS PaaS)
- 背包问题
- java后端系统架构之会话篇:sso单点登录会话介绍
- QML中树形控件TreeView的最基本、最简单粗暴的、一看秒懂的实现方法,之一
- HDU 3374 String Problem
- latex中长公式换行,很好的办法
- HDU 3068 最长回文
- C语言——排列组合