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

pku acm 2752 Seek the Name, Seek the Fame代码 pku acm 2752 Seek the Name, Seek the Fame代码<br>kmp算法。解题报告:http://blog.youkuaiyun.com/china8848 立即下载

题意:

给你一个串,如果这个串存在一个长度为n的前缀串,和长度为n的后缀串,并且这两个串相等,则输出他们的长度n。求出所有的长度n。

解析:

此题考察kmp next[]数组的应用,不难。

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int N = 400005;
char str[N];
int jump[N];

vector<int> ans;
void getNext() {
    int j = 0, k = -1;
    int len = strlen(str);
    jump[0] = -1;
    while(j < len) {
        if(k == -1 || str[j] == str[k])
            jump[++j] = ++k;
        else k = jump[k];
    }
}

int main() {
    while(scanf("%s", str) != EOF) {
        ans.clear();
        getNext();
        int cur = strlen(str);
        while(cur > 0) {
            ans.push_back(cur);
            cur = jump[cur];
        }
        sort(ans.begin(), ans.end());
        printf("%d", ans[0]);
        for(int i = 1; i < ans.size(); i++) {
            printf(" %d", ans[i]);
        }puts("");
    }
    return 0;
}
【例1896】report all clearance datasets 报告所有间隙数据集 report all clearance datasets 报告所有间隙数据集》这是一个NX二次开发官方小例子,下面是代码和解析。相较于混乱、未经验证的代码,官方案例能够确保开发者获得准确的开发方法,这些官方示例代码经过严格测试,能够正确地反映出NX软件的功能和API使用方式,有助于开发者系统地掌握NX二次开发技能,提高开发质量和效率。本专栏订阅后是永久阅读的。欢迎一起学习NX二次开发案例,逐步积累宝贵的经验,早日成为行业专家。 阅读详情

相关推荐

数字IC后端实现 | Innovus各个阶段常用命令汇总

数字IC后端设计实现之Innovus常用命令汇总

weixin_37584728的博客 7317

Seek the Name, Seek the Fame (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 ...

WhileTrue 1319

BIOS/UEFI完全指南:从开机自检到超频魔改的底层硬件控制

计算机启动过程始于固件层,其核心是负责硬件初始化与引导的系统软件。传统BIOS基于16位实模式,寻址能力有限,而现代UEFI采用保护模式,支持图形界面与安全启动,实现了从概念到架构的革新。这一演进带来了显著的技术价值:更快的启动速度、更强的安全性以及对大容量存储设备的原生支持。在工程实践中,无论是解决“虚拟化技术禁用”问题、调整内存XMP配置以提升性能,还是为老主板“魔改”添加NVMe支持,都需要深入理解并操作BIOS/UEFI设置。掌握这些底层交互能力,是进行硬件调试、系统优化与故障排查的关键,也是连接抽

weixin_34236869的博客 457

POJ 2752 Seek the Name, Seek the Fame / KMP

做了HDU 3336 这题小case k=next[n] 是最长的前缀 这题还要求不是最长的前缀 那么就 k = next[k] #include #include const int maxn = 400010; const int mod = 10007; char a[maxn]; int f[maxn]; int dp[maxn]; int n, flag; void print

嗯。 1205

UVM入门与进阶学习笔记17——寄存器模型(3)

目录寄存器模型的常规方法mirror、desired和actual valueprediction的分类自动预测显式预测uvm_reg的访问方法mem与reg的联系和差别内建(built-in)sequences寄存器模型内建序列存储模型内建序列寄存器健康检查寄存器应用场景寄存器检查功能覆盖率概述覆盖率自动收集模式覆盖率外部事件触发收集 寄存器模型的常规方法 mirror、desired和actual value 在应用寄存器模型时,除了利用它的寄存器信息,也会利用它跟踪寄存器的值。 寄存器模型中的每

weixin_41979380的博客 7536

【FF-A】第二章 Introduction

Armv8.4 架构引入了在安全状态下的虚拟化扩展。Arm® SMMU v3.2 架构[1]为安全流添加了对第2阶段翻译的支持,以补充在 Armv8.4 处理器状态下的安全 EL2 翻译制度。这些架构特性使得在安全状态下,彼此不信任的软件组件能够相互隔离。关于在安全状态下引入虚拟化扩展以及固件框架目标的更多理念可在名为《在安全世界使用虚拟化进行隔离》的白皮书[3]中找到。软件组件只能访问物理地址空间和系统资源的区域,例如 GIC 中对其正确运行必要的中断。

baron-周贺贺-代码改变世界ctw 528

POJ2752 Seek the Name, Seek the Fame【字符串匹配+KMP】

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

海岛Blog 4709

Sigrity System Explorer Transient Analysis模式进行瞬态仿真分析操作指导-差分信号

Sigrity System Explorer Transient Analysis模式可以用于瞬态仿真分析,通过搭建简易拓扑用于前仿真分析通道的时域性能,下面搭建一个简易的差分拓扑进行说明,以下图为例,准备好发送接收端的IBIS模型, (ibis_se.ibs,本例发送接收端都使用相同的IBIS模型),以及传输线的S参数模型(welement_se.sp)最上方的图形界面是传输线的模型,本例是一个上下都有参考平面的带状线,右侧的梯形是蚀刻角度,根据W1和W2以及铜厚来确定。

weixin_54787054的博客 440

poj 2752 Seek the Name, Seek the Fame

点击打开链接poj 2752 思路:kmp+next数组的应用 分析: 1 题意要求的找出满足既是字符串的s的前缀又是后缀的字串输出该字串的长度。 2 先看看next数组的含义: 1:next数组只和模式串本身有关和文本串是无关的,因为next表示的是当匹配失败后模式串要回溯到哪个位置。 2:next数组存储的数据是用来当模式串与主串不匹配的时候要模式串回退到第几个字符与主串再...

我是传奇 196

【Matlab】刃边法计算mtf

摘要:刃边法是一种测量光学系统调制传输函数(MTF)的常用方法。本文介绍了基于Matlab的MTF计算实现方案,包括图像灰度化、梯度计算、刀口方向选择、梯度投影等关键步骤,并给出了完整的代码实现。该方案可通过添加图像预处理、多方向计算、函数封装等方式进行扩展,提高MTF计算的准确性和实用性,适用于不同应用场景的光学系统性能评估需求。(148字)

unber的博客 389

Qt/C++ 音视频开发 - FFmpeg 安卓版

通过将 FFmpeg 集成到 Qt/C++ 项目中,我们可以实现强大且灵活的音视频处理功能。本文介绍了在安卓平台上使用 FFmpeg 的基本步骤,包括初始化、解码、处理和编码等。实际应用代码示例展示了如何在安卓设备上播放视频。

走向CTO的路上... 1190

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

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

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

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

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

ンZee的解题报告 2456

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

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

POJ_2752 Seek the Name, Seek the Fame 【KMP】

一、题目   POJ2752 二、分析   比较明显的KMP运用。   但是这题不是只找一个,仔细看题后可以发现相当于是在找到最大的满足条件的后缀后,再在这个后缀里面找满足条件的后缀。   可以不断的运用KMP得出答案,但是会超时。   寻找优化,发现答案在处理过的next数组中,因为题目中的条件就是前缀和后缀交集,那么前缀的串肯定与后缀的串相同,那么我们只需要改变长度继续分析就可以了...

weixin_30485291的博客 122

【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

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

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算法

题意: 给定若干字符串(这些字符串总长 ≤ 400000 ),在每个字符串中求出所有既是前缀又是后缀的子串长度。 例如:ababcababababcabab,既是前缀又是后缀的:ab,abab,ababcabab,ababcababababcabab。 题解: 使用kmp算法。我们知道next[i]是i之前的子字符串中相同前缀和后缀的最长长度。则可以这么考虑:从next[str.size(...

Aya_Uchida 409

POJ2752 Seek the Name, Seek the Fame KMP应用

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

Forjames的栏目 542

poj2752Seek the Name, Seek the Fame【kmp】

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

走一步再走一步 640

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

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

[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】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 784
上一篇: POJ 1961 Period(kmp循环节)
下一篇: POJ 3126 Prime Path(bfs)
HelloWorld10086
博客等级 码龄12年 88粉丝 614原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值