POJ 2752 Seek the Name, Seek the Fame(KMP 理解应用)

告别Keil手动分区!用CubeMX+VS Code一键生成带Bootloader的STM32 OTA工程 本文详细介绍了如何利用STM32CubeMX和VS Code实现STM32 OTA工程的自动化构建,告别传统Keil手动分区的繁琐流程。通过图形化配置Flash分区、自动生成链接脚本以及实现Bootloader跳转逻辑,开发者可以高效完成远程升级功能开发,显著提升嵌入式开发效率。 阅读详情
Seek the Name, Seek the Fame
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 9735 Accepted: 4670

Description

The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm: 

Step1. Connect the father's name and the mother's name, to a new string S. 
Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S). 

Example: Father='ala', Mother='la', we have S = 'ala'+'la' = 'alala'. Potential prefix-suffix strings of S are {'a', 'ala', 'alala'}. Given the string S, could you help the little cat to write a program to calculate the length of possible prefix-suffix strings of S? (He might thank you by giving your baby a name:) 

Input

The input contains a number of test cases. Each test case occupies a single line that contains the string S described above. 

Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000. 

Output

For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby's name.

Sample Input

ababcababababcabab
aaaaa

Sample Output

2 4 9 18
1 2 3 4 5

Source


这个题目只要对KMP有一定理解就能做了,题目意思是求一个串的所有前缀与后缀相同的串的长度

这个题目看见首先这个串就是一个,而且是最长的

然后就是对这个串求一次next求完之后就是输出结果

结果就是输出next[len]这个肯定不是本身最长的,然后不断next next就OK了

至于为什么这样其实理解了KMP是不难发现的

就拿题目中的串来讲解一下吧!

ababcababababcabab
0: -1 1: 0 2: 0 3: 1 4: 2 5: 0 6: 1 7: 2 8: 3 9: 4 10: 3 11: 4 12: 3 13: 4 14: 5 15: 6 16: 7 17: 8 18: 9 

看18位置的next是9,那么这个是一个答案,因为在位置18前面有9个字符是满足题目的串

然后跳到9的这个位置,发现就是答案,其实结果已经很明显了

18位置的next是9,那么9位置的next值前面的next值个字符和18前面的几个相同,而又与开始的

几个相同,这样就是后缀与前缀相同,就是题目要求的答案了!

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char str[500000];
int next[500000];
int ans[500000];
int pos;
int get_next(int i,int j)
{
next[0]=-1;
while(str[i])
{
if(j==-1 || str[i]==str[j])
{
j++;
i++;
next[i]=j;
}
else
j=next[j];
}
return i;
}
int main()
{
int i,j,k;
int len;
while(scanf("%s",str)!=EOF)
{
pos=0;
len=get_next(0,-1);
i=next[len];
while(i!=-1)
{
ans[pos++]=i;
i=next[i];
}
for(i=pos-2;i>=0;i--)
printf("%d ",ans[i]);
printf("%d\n",len);
}
return 0;
}




【学习体会】Lighttools8.4.0:矩形阵列光源+条形光源的光学仿真分析 在solidworks中设计了条形光源的基本结构: 由32*6个矩形led组成矩形光源阵列,如下所示 另存为step文件后,导入lighttools中,这里要设置模型的光学属性为:吸收体(机械) 因为我们设计的光源模型是一个整体,我们不能单个面的设置光源,比如说, 这样做的话并不会是这个面设置为光源,而是会把做一个模型都变成一个光源,如下 这显然不是我们想要的 那么,我们就在led位置上放置一个矩形面光源, 这样我们就放置好了一个面光源, 但是问题是,还有191... 阅读详情

相关推荐

双相机坐标系标定

工业双相机对位标定

sinat_33762356的博客 8331

POJ2752 Seek the Name, Seek the Fame【KMP】

POJ2752 Seek the Name,Seek the FamePOJ2752\ Seek\ the\ Name, Seek\ the\ FamePOJ2752 Seek the Name,Seek the Fame 【简要题意】 给定一个字符串,从小到大输出sss中既是前缀又是后缀的子串长度 【题解】 KMPKMPKMP比较裸的题,考察对KMPKMPKMP里nxtnxtnxt数组的理解 借用KMPKM

Young_Zn_Cu 140

BIOS更新后PIN不可用怎么办?从原理到实操的完整修复指南

在计算机维护中,BIOS更新是常见的固件升级操作,但其引发的登录异常却常让用户措手不及。Windows Hello PIN并非传统密码,它通过TPM芯片与设备启动环境(PCR状态)强绑定,一旦主板固件或安全启动配置改变,TPM便会拒绝释放密钥,导致“由于此设备上的更改,你的PIN不再可用”。理解这一原理后,恢复路径清晰可控:优先尝试密码登录,或通过WinRE替换utilman.exe创建临时管理员,必要时还需处理BitLocker恢复密钥。本文面向系统维护与数据安全场景,系统梳理PIN失效的恢复流程与避坑方

weixin_31364787的博客 419

KMP-Seek the Name, Seek the Fame-POJ - 2752

KMP-Seek the Name, Seek the Fame-POJ - 2752 题目: 给定若干只含小写字母的字符串(这些字符串总长≤400000),在每个字符串中求出所有既是前缀又是后缀的子串长度。 例如:ababcababababcabab,既是前缀又是后缀的子串:ab,abab,ababcabab,ababcababababcabab。 输入格式 输入若干行,每行一个字符串。 输出格...

njuptACMcxk的博客 349

stm32f103运行FreeRTOS使用DMA实现USART1不定长接收

使用DMA是实现USART1的不定长接收和发送数据。接收采用FIFO缓存和队列的方式向应用层抛数据。首先定义接收和发送的缓存区,缓存区的大小根据收发数据量确定。DMA接收开启转移完成和转移一般中断。在中断中从缓存向FIFO转移数据。串口开启空闲中断,实现接收数据的分帧。分帧后的数据节点通过写入到队列。发送数据缓存的大小根据发送数据量调整。然后初始化串口和DMA。串口的发送数据接口函数。...

polaris_zgx的博客 1992

LayaBox CommandBuffer描边使用详细

项目需要使用LayaBox做一个给3D物体动态描边的一个功能,前前后后踩了一些坑算是把这个东西给做出来了把我改好的代码贴上,分享给大家。 (1)想要使用描边你的引擎版本必须 >=2.9.0 (2)你必须下载 Laya官方的BlurShader库才能使用这个功能,下载地址:https://github.com/layabox/layaair-demo/tree/master/h5/3d/ts/LayaAir3D_PostProcess/BlurShader 下载完之后把BlurShader放到自己项目的

小智队长 1738

POJ 2752 Seek the Name,Seek the Fame

Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14048   Accepted: 6990 Description The little cat is so famous, that many coup

Moressette流沙的博客 409

Isaac Sim 车辆动力学:从参数调优到户外仿真的挑战与实战

本文深入探讨了Isaac Sim在车辆动力学仿真中的应用,从参数调优到户外场景模拟的实战经验。详细解析了悬架系统、轮胎物理模型等核心参数的设置技巧,并分享了应对户外仿真挑战的实用方案。通过Vehicle Wizard高级使用和传感器配置,帮助开发者高效完成车辆仿真与算法开发。

weixin_29192211的博客 408

[KMP]Seek the Name, Seek the Fame

题目来源: POJ 2752 & 奥赛一本通 1458 *Seek the Name, Seek the Fame 【题目描述】 原题来自:POJ 2752 给定若干字符串(这些字符串总长 ≤4×105​​ ),在每个字符串中求出所有既是前缀又是后缀的子串长度。 例如:ababcababababcabab,既是前缀又是后缀的:ab,abab,ababcabab,ababcababab...

qq_44684599的博客 414

Win11+VSCode+TeXLive:学术党必备的LaTeX环境配置避坑指南(2024最新版)

本文详细介绍了如何在Windows 11系统下,通过VSCode编辑器与TeXLive发行版配置高效的LaTeX学术写作环境。针对国内用户常见的镜像下载慢、插件配置复杂等问题,提供了优化方案和避坑指南,帮助科研人员和学生快速搭建流畅的学术写作工作流。

plum99的博客 634

【嵌入式笔试题】C语言笔试题(4)

嵌入式C语言综合笔试题

m0_74055118的博客 1074

POJ 2752:Seek the Name, Seek the Fame

Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13619 Accepted: 6755Description The little cat is so famous, that many couples tramp over hill and

787

DTI-ALPS处理笔记

前段时间刚好学习了一下DTI-ALPS处理(diffusion tensor image analysis along the perivascular space ),记录一下,以便后续学习。ALPS是2017年发表在《Japanese Journal of Radiology》的一篇文章首次提出的 (),主要用于无创评估脑内淋巴系统功能的衡量数值。C图和D图中的蓝色部分是投射纤维,绿色部分是联合纤维,红色部分是皮下纤维。

weixin_52073820的博客 4800

【题解】Seek the Name, Seek the Fame POJ - 2752 ⭐⭐ 【KMP】

Seek the Name, Seek the Fame POJ - 2752 给定若干只含小写字母的字符串(这些字符串总长≤400000),在每个字符串中求出所有既是前缀又是后缀的子串长度。 例如:ababcababababcabab,既是前缀又是后缀的子串:ab,abab,ababcabab,ababcababababcabab。 Input 输入若干行,每行一个字符串。 Output 对于每...

Suprit's blog 658

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

[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: 8261 Accepted: 3883 DescriptionThe little cat is so fam

Edt! 556

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

KMP POJ 2752 Seek the Name, Seek the Fame

Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15562 Accepted: 7875 Description The little cat is so famous, that many couples tramp over hill a

Dafang_Xu的博客 438

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

[kmp应用]Seek the Name, Seek the Fame POJ2752

The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the inn

Cloth的博客 120

[poj2752]Seek the Name, Seek the Fame_KMP

Seek the Name, Seek the Fame poj-2752     题目大意:给出一个字符串p,求所有既是p的前缀又是p的后缀的所有字符串长度,由小到大输出。     注释:$1\le strlen(p)\le 4\cdot 10^5$。       想法:显然,这样的所有的字符串必须满足一些性质。我们预处理出所有p的next数组。然后对于next[len],如果它...

dianan0938的博客 121

POJ 2752 Seek the Name, Seek the Fame——KMP

传送门 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such bor

lllllan 161

poj 2752 Seek the Name, Seek the Fame(KMP)

点击打开题目链接 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11198   Accepted: 5457 Description The little cat is so famous

risker_2013的专栏 544

poj 2752Seek the Name,Seek the Fame(KMP)

Seek the Name,Seek the Fame(pku 2752) 小猫非常有名,许多夫妇翻山越岭来到Byteland为了求小猫给他们新出生的孩子赐一个名字。为了应付这项无聊的工作,具有创新精神的小猫想到了一个简单却很神奇的程序:第一步:将父亲和母亲的名字连接在一起得到一个新的字符串S。 第二部:找到一个S的子串作为前缀-后缀字符串。所谓前缀-后缀字符串即S的子串不仅是S的前缀又是S的

The_star_is_at的博客 440

poj 2752 Seek the Name, Seek the Fame

Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12866   Accepted: 6346 Description The little cat is so famous, that many coup

ysCover 542

Seek the Name, Seek the Fame(信息学奥赛一本通- P1458)

题目明确说明“输入若干行”,必须使用。如果只读一次就会直接WA。使用(ull) 让计算机在超过2^64−1时自动截断,相当于自动对2^64取模。千万不要再手动去某个大质数,不仅拖慢运行速度,代码还容易写错。字符串很长且测试数据多,建议在main刚开始加上cin.tie(0);,否则容易被cin和cout卡常数导致超时。前缀的末尾是i,后缀的起点是N−i+1。这两个坐标在草稿纸上画一下就能确认,切忌凭感觉乱写导致错位。

布心老混子 所有代码均老混子本人远古手搓 易错点均为学生真实场景 博客文章部分借助ai生成 414

POJ - 2752 Seek the Name, Seek the Fame(对kmp中next数组的理解或hash)

题目链接:https://vjudge.net/contest/350796#problem/B Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-...

zaiyang遇见 305

POJ2752 Seek the Name, Seek the Fame KMP(KMP中对next数组原理的理解)

Problem Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at...

wcxyky的博客 187

POJ2752 “Seek the Name, Seek the Fame” (KMP算法)题解

Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 29748 Accepted: 15424 Description 题目链接:http://poj.org/problem?id=2752 The little cat is so famous, that many c...

H_define的博客 300
上一篇: POJ 3630 Phone List(trie 前缀)
下一篇: HDU 2594 Simpsons’ Hidden Talents(KMP理解应用)
sunrainchy
博客等级 码龄14年 14粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值