POJ 2752 Seek the Name, Seek the Fame (KMP)
传送门 http://poj.org/problem?id=2752
题目大意:求既是前缀又是后缀的前缀的可能的长度。。
同样是KMP,和 HDU 2594 Simpsons’ Hidden Talents ( http://blog.csdn.net/murmured/article/details/12867995) 一样,只不过这题是全部输出而已。
故利用失配函数性质,一路next(好吧我的代码是f),最后倒序输出
#include<cstdio>
#include<cstring>
const int MAXN=400000+10;
char P[MAXN];
int f[MAXN];
int n,m;
int ans[MAXN];
void getFail()
{
int i,j;
f[0]=f[1]=0;
for(i=1;i<n;i++)
{
j=f[i];
while(j && P[i]!=P[j])
j=f[j]; if(P[i]==P[j])
j++; f[i+1]=j;
}
} int main()
{
while(scanf("%s",P)!=EOF)
{
n=strlen(P);
getFail();
int len=0;
int j=n;
do
{
ans[len++]=j;
j=f[j];
}while(j); for(int i=len-1;i>=1;i--)
{
printf("%d ",ans[i]);
}
printf("%d\n",ans[0]); }
}
POJ 2752 Seek the Name, Seek the Fame (KMP)的更多相关文章
- poj 2752 Seek the Name, Seek the Fame (KMP纯模版)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13840 Ac ...
- poj-------------(2752)Seek the Name, Seek the Fame(kmp)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11831 Ac ...
- Seek the Name, Seek the Fame(Kmp)
Seek the Name, Seek the Fame Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (J ...
- 题解报告:poj 2752 Seek the Name, Seek the Fame(kmp前缀表prefix_table的运用)
Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...
- POJ 2752 Seek the Name, Seek the Fame(KMP求公共前后缀)
题目链接:http://poj.org/problem?id=2752 题目大意:给你一串字符串s找到所有的公共前后缀,即既是前缀又是后缀的子串. 解题思路: 如图所示 假设字符串pi与jq为符合条件 ...
- POJ 2752 - Seek the Name, Seek the Fame (KMP)
题意:给一个字符串s,问s的某个前缀与后缀相同的情况时,长度是多少. 此题使用KMP的next数组解决. next数组中,j=next[i],next[i]表示S[0...i-1]的某个后缀(字符串S ...
- POJ 2752 Seek the Name, Seek the Fame (KMP的next函数,求前缀和后缀的匹配长度)
给一个字符串S,求出所有前缀,使得这个前缀也正好是S的后缀.升序输出所有情况前缀的长度.KMP中的next[i]的意义就是:前面长度为i的子串的前缀和后缀的最大匹配长度.明白了next[i],那么这道 ...
- POJ 2752 Seek the Name, Seek the Fame(KMP中next的理解)题解
题意: 要求你给出每个前后缀相同的串的长度,比如: "alala"的前缀分别为{"a", "al", "ala", &q ...
- POJ-2752 Seek the Name, Seek the Fame(KMP,前缀与后缀相等)
题意: 给出一个字符串str,求出str中存在多少子串,使得这些子串既是str的前缀,又是str的后缀.从小到大依次输出这些子串的长度. 这个就是next数组的应用,next数组真是很深奥啊. ...
随机推荐
- 关于HashMap
总是觉得对HashMap很熟悉,但最近连续被问到几个关于它的问题,才发现它其实并不简单.这里对关于它的一些问题做个总结,也希望能够大家一个参考. 都知道它是基于hash值,可以进行常量时间消化的存储结 ...
- SAR(遥感、卫星) 图像常用数据集
Brazilian Coffee Scenes数据集较小,5MB左右: UC Merced Land Use Dataset(数据集规模较大,300MB+) MSTAR public targets ...
- Linux下ping命令、traceroute命令、tracert命令的使用
Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”.不能打开网页时会说“你先ping网关地址192.168.1.1试试”. ...
- Cloudera Hue是什么?
Hue是cdh专门的一套web管理器,它包括3个部分hue ui,hue server,hue db.hue提供所有的cdh组件的shell界面的接口.你可以在hue编写mr,查看修改hdfs的文件 ...
- IOS打包发布APP的所有详细流程
其他一些不错的参考:点击打开链接 一.申请苹果开发者账号 首先需要申请苹果开发者账号才能在APP store 里发布应用. 开发者账号分为:(1)个人开发者账号 (2)企业开发者账号 主要的区 ...
- recyclerview23+出现多个item只显示第一个item的问题
1.改成21+可以,如果不行,就使用第2或第3个解决方案 2.对每个item的inflate,传入两个参数,第二个参数设置为null,而不是使用3个参数(第二个parent,第三个false) 3.i ...
- javafx ComboBox Event and change cell color
public class EffectTest extends Application { public static void main(String[] args) { launch(args); ...
- SpringJunit测试类 BaseTest(转)
/** * * * @author Jerval * @date 2011-2-17 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfig ...
- ORM进阶:Hibernate的优劣对照
hibernate是一种是轻量级的ORMapping框架.学过EntityFramework的.会感觉挺亲切的. 对于各种层次程序猿对数据库的设计: 小菜程序员这样做:首先考虑数据的存储,对于功能的实 ...
- 前台技术--div的隐藏与显示
怎样使用页面元素隐藏或显示. HTML为我们提供了两个变量visibility和display visibility:隐藏要元素可是元素所暂用的空间不予释放.也就是说元素隐藏了,可是页面上会流出一片空 ...