一道KMP题目

求出next数组后就可以得知一个字串的最长前缀-后缀字串

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
inline int read(){int x=0,f=1,ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
char s[400005];
int len,nxt[400005];
inline void get_nxt(){nxt[0]=-1;int i=0,k=-1;while(i<len){if(k==-1||s[i]==s[k]) nxt[++i]=++k;else k=nxt[k];}
}
inline void get_ans(int x){if(x==0) return ;get_ans(nxt[x]);printf("%d ",x);
}
int main(){while(scanf("%s",s)!=EOF){// puts("X");len=strlen(s);get_nxt();get_ans(len);puts("");}return 0;
}

  

转载于:https://www.cnblogs.com/gcyyzf/p/9741000.html

POJ 2752 Seek the Name, Seek the Fame相关推荐

  1. KMP POJ 2752 Seek the Name, Seek the Fame

    题目传送门 1 /* 2 题意:求出一个串的前缀与后缀相同的字串的长度 3 KMP:nex[]就有这样的性质,倒过来输出就行了 4 */ 5 /**************************** ...

  2. 【hash】Seek the Name, Seek the Fame

    [哈希和哈希表]Seek the Name, Seek the Fame 题目描述 The little cat is so famous, that many couples tramp over ...

  3. KMP Seek the Name,Seek the Fame

    Seek the Name,Seek the Fame 时间限制: 1 Sec 内存限制: 128 MB 题目描述 给定一个字符串s,从小到大输出s中既是前缀又是后缀的子串的长度. 字符串长度不超过四 ...

  4. Seek the Name, Seek the Fame(KMP-next数组详解)

    Seek the Name, Seek the Fame 目录 Seek the Name, Seek the Fame 解题过程 举个例子 AC代码 The little cat is so fam ...

  5. [poj2752]Seek the Name, Seek the Fame_KMP

    Seek the Name, Seek the Fame poj-2752 题目大意:给出一个字符串p,求所有既是p的前缀又是p的后缀的所有字符串长度,由小到大输出. 注释:$1\le strlen( ...

  6. Seek the Name, Seek the Fame POJ - 2752 (理解KMP函数的失配)既是S的前缀又是S的后缀的子串

    题意:给一个字符串S, 求出所有前缀pre,使得这个前缀也正好是S的后缀. 输出所有前缀的结束位置. 就是求前缀和后缀相同的那个子串的长度  然后从小到大输出,主要利用next数组求解. 例如 &qu ...

  7. 【POJ - 2752】Seek the Name, Seek the Fame (KMP,公共前缀后缀长度及个数)

    题干: The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked t ...

  8. Seek the Name, Seek the Fame - POJ 2752(next运用)

    题目大意:小猫是非常有名气的,所以很多父母都来找它给孩子取名字,因为找的人比较多,小猫为了摆脱这个无聊的工作,于是它发明了一种取名字的办法,它把孩子父母的名字合在一起,然后从这个名字里面找一个前缀,并 ...

  9. Seek the Name, Seek the Fame POJ - 2752(KMP应用)

    Stringland有一只小猫非常有名,许多夫妇跋涉到Stringland请小猫为他们的新出生的婴儿起名字,他们寻求这个名字,同时寻求名声.为了摆脱这种无聊的工作,创新的小猫制定了一个简单而奇妙的算法 ...

  10. poj-2752 Seek the Name, Seek the Fame **

    /* * KMP **/ #include <cstdio>#include <cstring>using namespace std; const int maxL = 40 ...

最新文章

  1. Spring Cloud 万字总结!
  2. 移动中”的HTML5-开源图表库ichartjs-王鹤
  3. [linux] ubuntu gnome 控制面板恢复
  4. python如何实现选项功能_python几种常用功能如何实现 python几种常用功能实现代码实例...
  5. Git 基础 —— 常用命令
  6. [工作积累] UE4 TAA ReProjection的精度处理
  7. django数据库事务
  8. Pannellum:实例之一个简单的例子
  9. HTML命名空间的使用
  10. 推荐一款文献管理工具 Zotero |附使用教程和学习路径
  11. burpsuite之CSRF测试
  12. 名帖104 赵孟頫 楷书《崑山州淮云院记》
  13. Digital Signal Processing 数字信号处理
  14. matlab图源代码,[转载]常用的一些图像处理Matlab源代码
  15. 2022年零基础自学网络安全/Web安全,看这一篇就够了
  16. android softkeyboard,如何以编程方式关闭Android Soft KeyBoard?
  17. JAVA--发送Google邮件
  18. 名悦集团:春节小长假后汽车保养该怎么做
  19. 2023 thinkphp 福娃交易网站系统源码
  20. 信息网络传播中的服务器标准,信息网络传播权侵权认定标准适用研究

热门文章

  1. [html]window.open 使用示例
  2. [双调]落梅风(寿阳曲).焰火似龙
  3. 面向对象的关键技术(多态、接口、抽象)
  4. 【GCN+KG】基于知识图谱和图卷积神经网络的应用和开发
  5. 【论文推荐】结合KB和answer selection的相关论文推荐
  6. 【面经】深度学习算法岗(京东)
  7. 强烈推荐 | 算法/深度学习/NLP面试笔记
  8. 达观杯文本智能处理(1)
  9. 每周荐书:机器学习、Spring MVC、Android(评论送书)
  10. Android应用程序组件Content Provider简要介绍和学习计划 .