题目传送门

 1 /*
 2     题意:求出一个串的前缀与后缀相同的字串的长度
 3     KMP:nex[]就有这样的性质,倒过来输出就行了
 4 */
 5 /************************************************
 6 * Author        :Running_Time
 7 * Created Time  :2015-8-10 11:29:25
 8 * File Name     :POJ_2752.cpp
 9  ************************************************/
10
11 #include <cstdio>
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <bitset>
26 #include <cstdlib>
27 #include <ctime>
28 using namespace std;
29
30 #define lson l, mid, rt << 1
31 #define rson mid + 1, r, rt << 1 | 1
32 typedef long long ll;
33 const int MAXN = 4e5 + 10;
34 const int INF = 0x3f3f3f3f;
35 const int MOD = 1e9 + 7;
36 int nex[MAXN];
37 char str[MAXN];
38
39 void get_nex(void)  {
40     int len = strlen (str);
41     int i = 0, j = -1;  nex[0] = -1;
42     while (i < len) {
43         if (j == -1 || str[j] == str[i])    {
44             j++;    i++;    nex[i] = j;
45         }
46         else    j = nex[j];
47     }
48     vector<int> ans;
49     while (i != -1) {
50         ans.push_back (i);  i = nex[i];
51     }
52     for (int i=ans.size ()-2; i>=0; --i)    {
53         printf ("%d ", ans[i]);
54     }
55     puts ("");
56 }
57
58 int main(void)    {     //POJ 2752 Seek the Name, Seek the Fame
59     while (scanf ("%s", str) == 1)  {
60         get_nex ();
61     }
62
63     return 0;
64 }

转载于:https://www.cnblogs.com/Running-Time/p/4717781.html

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

  1. KMP Seek the Name,Seek the Fame

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

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

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

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

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

  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. Seek the Name, Seek the Fame POJ - 2752 (理解KMP函数的失配)既是S的前缀又是S的后缀的子串

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

  6. 【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 ...

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

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

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

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

  9. KMP POJ 3461 Oulipo

    题目传送门 1 /* 2 题意:问一个串在另一个串出现的次数(可重复) 3 KMP:模板题 4 */ 5 /********************************************** ...

最新文章

  1. 在ViT、MLP-Mixer等进行4800多次实验,谷歌发现大规模预训练存在瓶颈
  2. 页面放在哪_seo页面怎么优化?seo页面优化有哪些方法?
  3. TwoSum,从O(n^2)到O(nlogn)再到O(n)
  4. Security+ 学习笔记56 增强隐私保护的技术
  5. springmvc配置拦截器
  6. ssd网络结构_SSD的理解
  7. 快速批量重命名文件(夹)
  8. VR全景航拍:初学者如何做好全景航拍?
  9. php 图片汉字命名_基于php上传图片重命名的6种解决方法的详细介绍
  10. 信息收集汇总(附网盘泄露工具)
  11. linux版电脑卡顿,教程方法;linux系统很卡的基本排查方法介绍电脑技巧-琪琪词资源网...
  12. 制作U盘启动CDLinux
  13. python基础读后感_Python基础教程【读书笔记】 - 2016/6/26
  14. 鸿蒙系统中的 WebView 加载H5页面出现net::ERR_CLEARTEXT_NOT_PERMITTED的解决方法
  15. ubuntu 下语系编码转换
  16. C语言函数没有return时会返回什么
  17. Sanic学习——初识Sanic
  18. Internet download manager下载外网问题
  19. vue打包部署,解决更新版本清理缓存问题
  20. WIN10出现“PL2303HXA自2012已停产,请联系供货商“解决办法

热门文章

  1. ise的时钟ip核_Vivado CIC IP核滤波器详解(一)
  2. python excel 数据匹配实现vlookup功能_如何用python实现excel中的vlookup功能?
  3. 台式电脑怎么找不到计算机在哪,台式机没有蓝牙怎么办
  4. android 动态添加颜色,Android绘制一个三角形并且可动态改变颜色
  5. java客户端_Java常用的Http client客户端
  6. java 序列化保存_保存到二进制/序列化Java
  7. 关于JSP页面无法加载css,游览器访问jsp页面样式未生效导致乱序
  8. w ndows10即将停止更新,微软开始警告Windows 10 v1909用户即将停止更新服务
  9. 《软件需求分析(第二版)》第 11 章——一图胜千言 重点部分总结
  10. springmvc中使用MockMvc测试controller