Seek the Name, Seek the Fame (kmp)

5、AIX系统硬件管理与故障诊断全解析 本文全面解析了AIX系统的硬件管理与故障诊断方法,涵盖系统管理服务(SMS)的使用、设备兼容性配置、设备配置数据库结构、常用命令如cfgmgr、lsattr、smitty devices的操作详解,并深入介绍了错误日志管理机制,包括errdemon、errpt、errlogger等命令的应用。通过实际案例分析和流程图展示,帮助系统管理员掌握从问题怀疑到诊断执行再到日志清理的完整流程,同时提供注意事项与最佳实践,助力AIX系统的稳定运行与高效维护。 阅读详情

Seek the Name, Seek the Fame


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
这道题很明显的是要求kmp中的next数组,但是要搞懂题意。

题目让我么求得是既是整个字符串的前缀又是后缀的,所以答案并不是next数组的每一个数。

首先字符串本身就是一个,然后求出next数组后next[len]其实就是整个字符串的前后缀最长长度,这样我们有求出一个长度,然后根据已经得到的最长的原本字符串的前后缀公共子串,我们通过i = next【i】就可以求得这个公共子串的子串,当然也是原字符串的的前后缀子串了。

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 1010000;
char s[MAXN];
int Next[MAXN];
int ans[MAXN];
void getNext(){
    int i = -1,j = 0;
    int lens = strlen(s);
    Next[0] = -1;
    while(j < lens){
       if(i == -1 || s[i] == s[j]){
          i++,j++;
          Next[j] = i;
       }
       else
          i = Next[i];
    }
    return;
}
int main(){
    while(~scanf("%s",s)){
       getNext();
       int cnt = 0;
       int i;
       for(i = strlen(s); Next[i] != -1; i = Next[i]){
           ans[cnt++] = i;
       }
       printf("%d",ans[cnt-1]);
       for(i = cnt-2; i >= 0; i--){
           printf(" %d",ans[i]);
       }
       printf("\n");
    }
    return 0;
}



模型实战(31)之 yolo26 实现对手部关键点数据集 的训练与关键点检测 阅读详情

相关推荐

TP4054芯片实战:手把手教你设计USB锂电充电电路(附PCB散热优化技巧)

本文以TP4054芯片为核心,手把手教你设计稳定可靠的USB锂电池充电电路。文章详细解析了芯片的恒流恒压工作模式、关键外围元件选型计算,并重点分享了PCB布局与散热优化的实战技巧,帮助工程师从“能工作”提升到“工作得好”,确保充电效率与系统稳定性。

1a2s3d4f5g的博客 467

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

计算机科学与技术专业学生的成长之路 775

Matlab实现PSO-TCN-LSTM-Attention粒子群算法优化时间卷积长短期记忆神经网络融合注意力机制多变量时间序列预测的详细项目实例

这些数据包含了随时间变化她动态信息,具有显著她趋势她、周期她和季节她特征。该模型她核心优势在她其能够自适应地学习数据中她多层次时序信息,捕捉时间序列中她长短期依赖关系,从而提高预测她准确她和可靠她。本项目旨在实她一个基她PTO-TCN-LTTM-TFSttfntion她多变量时间序列预测模型,通过粒子群优化算法优化时间卷积长短期记忆神经网络,并融合注意力机制,提高模型她预测精度和稳定她。本项目模型她实她分为多个阶段,首先她数据预处理,接着她PTO优化,然后她TCN和LTTM网络她构建她训练。

优质创作者: 人工智能技术领域 对于有一定基础的 MATLAB和Python带具体需求都可以详谈 MATLAB和Python可以提供代码调试服务加油 谢谢 你的鼓励是我前行的动力 谢谢支持 加油 谢谢 1078

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

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

m0_58245389的博客 387

彩票预测的可能性与算法分析

彩票作为一种以随机数为基础的赌博形式,吸引了大量希望一夜暴富的参与者。尽管许多人希望通过某种方式预测彩票结果,以增加中奖几率,但彩票预测的可能性依然是一个充满争议和误解的话题。本文将探讨彩票是否能够预测的理论依据,分析可能的预测算法,并解释这些算法为何在实际应用中难以奏效。

m0_38012434的博客 2万+

Reactor 响应式编程(第一篇:Reactor核心)

响应式:响应式编程: 全异步、消息、事件回调默认还是用当前线程,生成整个流、发布流、流操作.log();//只要不指定线程池,默认发布者用的线程就是订阅者的线程;

moments的博客 1571

Seek the Name, Seek the Fame(找名字,要成名)

poj 2752 题目大意:前边的串和后边的串相同的字符的个数 解决:kmp的next值,代表前边有多少和从开头的字符串相同 #include <iostream> #include <cstdio> #include <cstring> using namespace std; char str[400005]; int ne...

angel774422的博客 173

Pytorch版deeplabv3+环境配置训练自己的数据集

参考:https://blog.youkuaiyun.com/qq_36766560/article/details/110009622?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522161594607816780266214828%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=161594607816780266214828

Ring__Rain的博客 1万+

字符串——Seek the Name, Seek the Fame(kmp应用)

思路:一般的kmp处理完每个位置都只会有一个next值,所以这里并不能。但kmp具有一个很强的性质。题意:给一个字符串s,要求所有最后一个字符结尾的相同前缀和后缀的长度,自身也算。

测试 567

工业级AI智能体落地:OpenClaw+ONNX Runtime全栈部署,端到端延迟压至12ms

OpenClaw+ONNX的组合为工业AI智能体的落地提供了一套完整、高效、安全的解决方案。它解决了传统云端智能体在工业场景中面临的延迟、安全和稳定性问题,实现了本地数据闭环和毫秒级响应。未来,随着边缘计算和轻量级大模型技术的发展,工业AI智能体将变得更加智能和强大。我们可以预见,在不久的将来,工厂里的每一台设备都将拥有自己的AI智能体,它们能够自主感知、自主决策、自主执行,真正实现工业生产的全自动化和智能化。👉 点击我的头像进入主页,关注专栏第一时间收到更新提醒,有问题评论区交流,看到都会回。

2601_94871597的博客 735

PD3.0详解 协议的时序timer和counter计数

前面介绍了关于PD协议的交互,还有协议层数据各个字段的含义,但是一直没有系统的说关于协议的时序,还有部分counter,就是协议允许发送的次数,或者一些其他计数。 大师匈今天说一下关于这方面的东西,这些东西都是非常关键的东西,但是相对来说PD标准内对时序的要求还是比较宽泛,非常容易能够实现这样的要求。 Timer 1、CRCReceiveTimer 0.9~1.1ms 表示每次通信收到goodcrc的时间,必须在这个时间内收到goodcrc, 我们要注意不是在0.9~1.1ms内,而是第三方可以在这个范

大师匈的博客 5005

Seek the Name, Seek the Fame (KMP) 和(HASH)两种方法

#include &lt;stdio.h&gt; #include &lt;string.h&gt; #define maxn 400010 char a[maxn]; int nxt[maxn] ; int len; void getnxt() { nxt[0]=0; int i=1,j=0; while(i&lt;len) { if(a[i]==a[j]) { nxt[...

qq_42434171的博客 1495

水文仿真软件:SWMM (Storm Water Management Model)_(6).地理信息系统(GIS)与SWMM数据交换

地理信息系统(GIS)与SWMM数据交换是水文仿真中的一个重要环节。通过合理的数据准备、导入、导出和校验,可以确保模型的准确性和实用性。本文介绍了使用SWMM GIS Add-on和Python脚本进行数据交换的方法,并提供了一些优化建议和常见问题的解决方案。希望这些内容能帮助读者更好地进行GIS与SWMM的数据交换,提高水文仿真的效率和质量。

kkchenjj的博客 577

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

POJ 2752 Seek the Name, Seek the FameDescriptionThe 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. T

This is Mendez. 702

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

KMP之Seek the Name, Seek the Fame

Seek the Name, Seek the Fame   题目描述: 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. Th

loterior的博客 340

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

[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

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

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

海马有力量的博客 719

Seek the Name, Seek the Fame (KMP)

题目链接: Seek the Name, Seek the Fame 题目大意: 给定一个字符串,现在要找一些跟给定的字符串的前缀和后缀相同的字符串的长度。 题解: 利用KMP里面的next数组解决这一道题 我们用next数组求出来的是跟后缀相同的前缀,也就是上图中的左边的红色绿色和右边的红色绿色,那么如果说左边的红色和绿色相同的话,也就意味着左边的绿色等于右边的绿色,也就是前面的...

BigZong 630

kmp Seek the Name, Seek the Fame

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 sa

杭锦泉的博客 214

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

[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! 555

poj 2752Seek the Name, Seek the Fame 【kmp】

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

每个人的心中都藏着一个衰小孩儿 443

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

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

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

MADE_Y 700

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

题目链接:  poj 2752 题目大意:  给出字符串,找出所有的前缀和后缀相等的子串                   按小到大输出这些子串的长度 解题思路:                                  如图所示,根据next[  ]前缀的性质左边有颜色部分和右边有颜色部分完全相等                   因为左边的红色和右边的红色相等,

ンZee的解题报告 2456

【KMP】 poj2752 Seek the Name, Seek the Fame

Seek the Name, Seek the Fame http://poj.org/problem?id=2752 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give

Ted's 游乐园 663
上一篇: Power Strings
下一篇: Count the string(kmp+dp)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值