POJ2752 Seek the Name, Seek the Fame KMP应用

告别付费!手把手教你用DataV.GeoAtlas获取全国街道级GeoJSON数据(附完整避坑指南) 本文详细介绍了如何免费使用阿里云DataV.GeoAtlas工具获取全国街道级GeoJSON数据。通过可视化选取、格式转换、数据校验等步骤,提供了一套完整的避坑指南和工作流,帮助前端和可视化开发者高效解决高精度地图数据获取难题,节省成本并提升开发效率。 阅读详情

POJ2752 Seek the Name, Seek the Fame

这算是一道比较脑洞的KMP题目。
先来看题意。对于给定的一个字符串,有一部分前缀和后缀是相同的,让你从小到大输出这些相同前缀后缀的长度。
如样例 ababcababababcabab,相同的前缀后缀有“ab”,”abab”,”ababcabab”,”ababcababababcabab”四个,长度分别为2 4 9 18;

然后来看一看解法:
这里写图片描述
对于一个字符串 s[0…n-1] ,假设 s[0…i] , s[j…n-1] 是相同的,那么所有比它小的前缀后缀,如 s[0…x] , s[y…n-1] 都可以放在s[0…i]中( s[0…x] , s[z…i] )。那么,我们就可以从n-1开始,从大到小找。


代码
#include <iostream>
#include <stack>
#include <cstring>
using namespace std;

char s[400005];
int next[400005];
stack <int> st;

void get_next(int len){ // 求next数组
    int i = 0, j = -1;
    next[0] = j;
    while(i != len){
        if(j == -1 || s[i] == s[j]) next[++i] = ++j;
        else j = next[j];
    }
}

int main(){
    while(cin >> s){
        int l = strlen(s);
        get_next(l);
        int i = l;
        while(i != 0){ // 从长度l开始,直到i == 0为止
            st.push(i);//把答案放在栈中,反向输出。
            i = next[i];
        }
        while(!st.empty()){//利用栈的特性,后入先出,即可满足题目要求
            cout << st.top()<<' ';st.pop();
        }
        cout << endl;
    }


    return 0;
}
CV领域交叉注意力机制:QKV在图像特征增强中的核心作用解析 本文深入解析了CV领域中交叉注意力机制的核心组件QKV在图像特征增强中的关键作用。通过通俗类比和实战案例,阐述了Q(查询)、K(键)、V(值)如何协同实现动态权重分配,从而在目标检测、图像分割与生成等任务中显著提升模型性能与语义对齐能力。 阅读详情

相关推荐

[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

Python实现ARIMA模型

以下是一个使用Python实现ARIMA(自回归移动平均模型)的简单示例代码。在运行代码之前,请确保已经安装了pandasnumpy和库。ARIMAorder(2,0,2)p = 2d = 0q = 2forecastmatplotlib在实际应用中,你需要将模拟数据替换为真实的时间序列数据,并且通过合适的方法(如信息准则等)来确定pdq的最佳值。除了auto_arima在使用pmdarima。

huanghm88的专栏 1750

【POJ 2752 Seek the Name, Seek the Fame kmp】kmp&nex应用

A - Seek the Name, Seek the Fame Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u SubmitStatus Description The little cat is so famous, that many couples tramp over hill

ATOD 786

计算机组成原理实验(已通关)-华中科技大学头歌Educoder(Logisim)

汉字国标码转区位码实验 汉字机内码获取实验 8位可控加减法电路设计 第2关 CLA182四位先行进位电路设计 第3关 4位快速加法器设计 第4关 16位快速加法器设计 第5关 32位快速加法器设计 第6关 5位无符号阵列乘法器设计 6位有符号补码阵列乘法器 乘法流水线设计 原码一位乘法器设计 偶校验编码设计 偶校验解码电路设计 16位海明编码电路设计 16位海明解码电路设计 海明编码流水传输实验 16位CRC并行编解码电路设计 CRC编码流水传输实验

紫荆鱼的博客 4万+

《工程测量学》笔记/期末复习资料

《工程测量学》笔记/期末复习资料。

@HNUSTer的博客 5572

POJ - 2752 Seek the Name, Seek the Fame KMP中 nxt[ ] 应用

POJ - 2752 Seek the Name, Seek the Fame 题意: 寻找整串字符中前缀和后缀相同的,并从小到大输出长度 思路: 设字符串长度为 n ,t = nxt[n] 从t 往前找,如果 t 大于 0 ,则有长度为 t 的相同的前后缀,下一步 t = nxt[t] ,继续往下寻找。直到 t 小于等于 0 为止。 例如:ababcababababcabab    ...

没有梦想何以远行 181

【浙大翁恺】C语言习题

/* 02-0. 整数四则运算(10) 本题要求编写程序,计算2个正整数的和、差、积、商并输出。 题目保证输入和输出全部整型范围内。 输入格式: 输入在一行中给出2个正整数A和B。 输出格式: 在4行中按照格式“A 运算符 B = 结果”顺序输出和、差、积、商。 输入样例: 3 2 输出样例: 3 + 2 = 5 3 - 2 = 1 3 * 2 = 6 3 / 2 =.

qq_43600867的博客 5905

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

要解决这道题,首先要理解KMP中的next数组,现在觉得这个next数组真的很重要啊!!! 要找到一个字符串的所有的既是前缀又是后缀的子串的长度,那么就要知道,next指针的的含义,指向最长既是前缀又是后缀的前缀位置的后一位,那么一个对于一个位置的next的指针的位置的next指针指向的位置,于当前位置来说是什么意义呢?其实就是一个当前位置为止,既是前缀又是后缀的前缀的后一位,只不过不再是最长的

AClion的专栏 1081

实现AI Agent的多Agent协作能力

在当今复杂的计算环境和应用场景中,单个AI Agent的能力往往受到限制。实现AI Agent的多Agent协作能力的目的在于通过多个Agent之间的协同工作,充分发挥各自的优势,提高整体系统的性能和效率,以解决更为复杂的问题。本文章的范围涵盖了多Agent协作的核心概念、算法原理、数学模型、项目实战以及实际应用场景等方面,旨在为读者提供全面且深入的技术指导。本文将按照以下结构进行阐述:首先介绍多Agent协作的背景知识,包括目的范围、预期读者和文档结构等;

AI Python 编程之道的博客 1486

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

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

Stringland有一只小猫非常有名,许多夫妇跋涉到Stringland请小猫为他们的新出生的婴儿起名字,他们寻求这个名字,同时寻求名声。为了摆脱这种无聊的工作,创新的小猫制定了一个简单而奇妙的算法: 第一步、将父亲的姓名和母亲的姓名连接到一个新的字符串S. 第二步、找一个 S 的前缀-后缀串作为新生儿的名字(前缀-后缀串是S的前缀,又是S的后缀) 比如:父亲='ala',母亲='la',我们有...

博客 228

vb 6.0并口开发操作实例

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

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

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

o f f i c的博客 681

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

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

POJ 2752 Seek the Name, Seek the Fame(字符串前缀后缀,KMP算法应用)

题目来源:http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24318   Accepted: 12673 ...

da_kao_la的博客 329

POJ2752 Seek the Name, Seek the Fame KMP-next数组的应用

题目大意:给你一个字符串,让你找出既是前缀同时又是后缀的子串在主串中的位置,如果有多个,按升序输出。 分析:考察KMP算法中对next数组的理解。我们知道next[ j ]纪录的是字符串第j个位置之前的next[ j ]个连续的字符和该串的长度为next[ j ]的前缀是相同的。既然如此,要判断一个后缀是否等于前缀,只需看next[ len ]是否等于0即可,next[ len ]!=0

AC_Gibson的专栏 435

POJ 2752 Seek the Name, Seek the Fame kmp失配函数next应用

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

代码改变世界,keep coding。 1017

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

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

sunrain的专栏 821

POJ 2752 Seek the Name, Seek the Fame(KMP next数组应用)

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

布生气 1272

POJ 2752 Seek the Name, Seek the Fame(KMP next数组的应用)

http://poj.org/problem?id=2752 题目大意: 从小到大输出    串S中既是前缀又是后缀的子串的长度 分析: 题意就是next数组嘛      next数组从后往前      如果str[next[i]]==str[length-1]     记录一下长度

MM__1997的博客 350

POJ-2752 Seek the Name, Seek the Fame(kmp中next数组的应用)

H - Seek the Name, Seek the Fame Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice POJ 2752 Description The little cat is so famous, t

信仰.的博客 487

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

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

Darkarts 486

POJ 2752 Seek the Name, Seek the Fame(KMP的Next数组应用)

题目链接:http://poj.org/problem?id=2752DescriptionThe 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...

baodream的博客 180

Poj2752--Seek the Name, Seek the Fame(Kmp → → Next数组应用)

Seek the Name, Seek the Fame Time Limit:2000MS Memory Limit:65536K Total Submissions:14172 Accepted:7055 Description The little cat is so famous, that many cou...

dixi7825的博客 121

Seek the Name, Seek the Fame POJ 2752【KMP next数组的应用】

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

Determined&Diligent的专栏 363

POJ - 2752 Seek the Name, Seek the Fame (KMP的next[]应用)

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

那些年 1221
上一篇: poj1836 Alignment LIS傻逼题
下一篇: POJ3461 Oulipo KMP裸题
Forjames
博客等级 码龄11年 1粉丝 12原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值