题意:给你一个字符串,寻找前缀和后缀相同的子串(包括原串)、 从小到大排列输出其子串的长度

思路:KMP  next 数组应用、

其实就是一个数学推导过程、

首先由next数组 可知s(ab) = s(bd)   此时next[d]=b   而此时 next[b]=f,意味着s(ef)=s(gh)

 s(gh)属于s(ab)   s(ab)=s(bd);   所以可以推出 s(gh)属于s(bd)    且s(ef)=s(gh)  所以 s(ef)属于s(cd)

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
const int qq=400000+10;
char node[qq];
int next[qq];
int get[qq];
int len;
void getnext()
{
int i,j;
i=0;j=-1;
next[0]=-1;
while(i<len){
if(j==-1||node[i]==node[j])
next[++i]=++j;
else
j=next[j];
}
return;
}
int main()
{
while(~scanf("%s",node)){
len=strlen(node);
getnext();
int k=len;
int i=0;
while(next[k]!=0){ // 那个公式的推导体现在这里、
get[i++]=next[k];
k=next[k];
}
for(int j=i-1;j>=0;--j)
printf("%d ",get[j]);
printf("%d\n",len);
}
return 0;
}

POJ 2752 Seek the Name, Seek the Fame next数组理解加深的更多相关文章

  1. (KMP)Seek the Name, Seek the Fame -- poj --2752

    http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536 ...

  2. Seek the Name, Seek the Fame POJ - 2752

    Seek the Name, Seek the Fame POJ - 2752 http://972169909-qq-com.iteye.com/blog/1071548 (kmp的next的简单应 ...

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

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

  4. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  5. poj 2752 Seek the Name, Seek the Fame(KMP需转换下思想)

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10204   Ac ...

  6. poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14106   Ac ...

  7. POJ 2752 Seek the Name, Seek the Fame(next数组运用)

    Seek the Name, Seek the Fame Time Limit: 2000MS        Memory Limit: 65536K Total Submissions: 24000 ...

  8. POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)

    Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...

  9. 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 ...

随机推荐

  1. Handling Missing Values

    1) A Simple Option: Drop Columns with Missing Values 如果这些列具有有用信息(在未丢失的位置),则在删除列时,模型将失去对此信息的访问权限. 此外, ...

  2. web前端学习常用网址记录

    jetbrains下载各种软件和试用 www.jetbrains.com www.jetbrains.com/idea php服务器下载 php文档查询 php.net webAPI网站(各种教程文档 ...

  3. LintCode刷题笔记-- BackpackII

    标记: 动态规划 问题描述: Given n items with size Ai, an integer m denotes the size of a backpack. How full you ...

  4. iOS 使用Quartz和OpenGL绘图

    http://blog.csdn.net/coder9999/article/details/7641701 第十二章 使用Quartz和OpenGL绘图 有时应用程序需要能够自定义绘图.一个库是Qu ...

  5. 2019-11-20-WPF-使用-MyScript-的-IInk-做手写识别

    title author date CreateTime categories WPF 使用 MyScript 的 IInk 做手写识别 lindexi 2019-11-20 08:18:26 +08 ...

  6. PHP7捕获错误异常方法

    这种 Error 异常可以像 Exception 异常一样被第一个匹配的 try / catch 块所捕获.如果没有匹配的 catch 块,则调用异常处理函数(事先通过 set_exception_h ...

  7. PHP学习(类和对象)——基本概念

    类是面向对象程序设计的基本概念,通俗的理解类就是对现实中某一个种类的东西的抽象, 比如汽车可以抽象为一个类,汽车拥有名字.轮胎.速度.重量等属性,可以有换挡.前进.后退等操作方法. 每个类的定义都以关 ...

  8. 下载安装APK(兼容Android7.0)

    我们使用手机的时候经常会看到应用程序提示升级,大部分应用内部都需要实现升级提醒和应用程序文件(APK文件)下载. 一般写法都差不多,比如在启动app的时候,通过api接口获得服务器最新的版本号,然后和 ...

  9. DTcms设置 IIS6.0设置url重写导致editor上传全部失效

    1.修改iis的重写规则为htm 2.修改后台后缀为htm 解决

  10. Docker for windows pull镜像文件的安装位置改变方法

    发生现象: 在windows10下安装docker for windows,随着用docker pull image文件后,C盘的容量越来越小了,你可能也有一种跟我一样的想法,想改变默认的安装路径,本 ...