POJ 2752 Seek the Name, Seek the Fame next数组理解加深
题意:给你一个字符串,寻找前缀和后缀相同的子串(包括原串)、 从小到大排列输出其子串的长度
思路: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数组理解加深的更多相关文章
- (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 ...
- 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的简单应 ...
- KMP POJ 2752 Seek the Name, Seek the Fame
题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...
- 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 ...
- 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 ...
- 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 ...
- POJ 2752 Seek the Name, Seek the Fame(next数组运用)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24000 ...
- POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)
Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...
- 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 ...
随机推荐
- GDOI2017第四轮day1总结
总的来说这场比赛,只能说是勉强正常发挥. 实在是知识水平有限,最后没能突破瓶颈. 有几个做得好的地方: 1.想好了在写题: 2.暴力也会拍 3.适当地放弃题. 要学习的东西: 1.Sg,线性基: 2. ...
- JDK8 Stream 数据流效率分析
JDK8 Stream 数据流效率分析 Stream 是Java SE 8类库中新增的关键抽象,它被定义于 java.util.stream (这个包里有若干流类型: Stream<T> ...
- mysql5.7以上版本安装
首先下载mysql5.7zip版本 https://dev.mysql.com/downloads/mysql/5.7.html#downloads 然后放在本地解压 下载5.6版本 https:// ...
- 第一份Markdown。。。。。菜鸟给跪了
#First Markdown ##Hello World ###Ahaha - Python - Ruby - C++ - Haskell - C - Java 1. C 2. C++ 3. C# ...
- 如何用Excel打开CSV文件
如何用Excel打开CSV文件? CSV文件一般是MS-SQL 导出查询数据的一种格式.格式结构是 用逗号分隔数据,如果直接用Excel打开那么数据不会自动分列.需要进行一定的设置.下面是设置过程. ...
- date、cal和clear命令
一.date命令 date命令的功能:date命令是显示或设置系统时间与日期. 很多shell脚本里面需要打印不同格式的时间或日期,以及要根据时间和日期执行操作.延时通常用于脚本执行过程中提供一段等待 ...
- Directx教程(28) 简单的光照模型(7)
原文:Directx教程(28) 简单的光照模型(7) 现实生活中的点光源都是随着距离衰减的,比如一个电灯泡在近处会照的很亮,远处光线就很弱.本节中我们在前面光公式的基础上,再给漫反射和 ...
- 使用Data Lake Analytics读/写RDS数据
Data Lake Analytics 作为云上数据处理的枢纽,最近加入了对于RDS(目前支持 MySQL , SQLServer ,Postgres 引擎)的支持, 这篇教程带你玩转 DLA 的 R ...
- 使用哈工大LTP进行文本命名实体识别并保存到txt
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/broccoli2/article/det ...
- OpenCV在各版本上的安装教程
目录 使用pip安装OpenCV 安装Python版的OpenCV 4 安装Python版的OpenCV 3 在OSX和 macOS上安装OpenCV 3 在Ubuntu上安装Python版的Open ...