【poj2752】Seek the Name, Seek the Fame(KMP)
来源:互联网 发布:淘宝近视眼镜店 编辑:程序博客网 时间:2024/05/27 20:47
题目描述
传送门
题解
从后往前不断地找失配即可。
代码
#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int max_w=400005;char W[max_w];int len,T[max_w],ans[max_w],tot;inline void calc_T(){ T[0]=-1; int j; for (int i=0;i<len;++i){ j=T[i]; while (j!=-1&&W[i]!=W[j]) j=T[j]; T[i+1]=++j; }}inline void calc_ans(){ int j=len; while (j!=-1){ ans[++tot]=j; j=T[j]; }}int main(){ while (gets(W)){ memset(T,0,sizeof(T)); len=strlen(W); calc_T(); memset(ans,0,sizeof(ans)); tot=0; calc_ans(); for (int i=tot-1;i>=1;--i) printf("%d%c",ans[i]," \n"[i==1]); }}
0 0
- 【poj2752】Seek the Name, Seek the Fame(KMP)
- 【POJ2752】Seek the Name, Seek the Fame(KMP)
- poj2752 Seek the Name, Seek the Fame(KMP)
- 【KMP】 poj2752 Seek the Name, Seek the Fame
- poj2752 Seek the Name, Seek the Fame--------KMP
- poj2752 Seek the Name, Seek the Fame KMP
- POJ2752 Seek the Name, Seek the Fame 【KMP】
- POJ2752 Seek the Name, Seek the Fame KMP算法
- POJ2752 Seek the Name, Seek the Fame【KMP】
- POJ2752 Seek the Name, Seek the Fame(KMP)
- POJ2752 Seek the Name, Seek the Fame(kmp)
- 【poj2752】Seek the Name, Seek the Fame KMP
- POJ2752 Seek the Name, Seek the Fame KMP
- poj2752 Seek the Name, Seek the Fame (kmp)
- POJ2752 Seek the Name, Seek the Fame KMP应用
- kmp算法 poj2752 Seek the Name, Seek the Fame
- 【POJ2752】Seek the Name, Seek the Fame-KMP思想
- kmp杂题3 poj2752 Seek the Name, Seek the Fame
- c++ vector 动态数组用法
- 解决VM克隆CentOS系统后eth0消失,显示eth1的问题
- 1016. Phone Bills (25)
- TCP 握手失败事件-小记a
- 140 php $_SERVER变量
- 【poj2752】Seek the Name, Seek the Fame(KMP)
- 详解Android中的屏幕方向类型
- Objective-C编码规范:26个方面解决iOS开发问题
- Activity的状态保存
- 设计模式---状态模式
- UITableView回滚到顶部的几种方法
- storm-(1)集群安装及部署
- Android-中文转拼音
- centos安装tomcat7