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

别再羡慕专业版!用这个批处理脚本,一键给Win11家庭版装上官方沙盒 本文详细介绍了如何通过批处理脚本在Windows 11家庭版上安装官方Windows沙盒(Windows Sandbox),无需复杂操作即可享受专业版功能。脚本自动激活系统内置组件,提供安全隔离的虚拟化环境,适用于软件测试、安全浏览等场景。 阅读详情

A - Seek the Name, Seek the Fame
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit

Status
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

题意:给你一个字符串,求所有前缀等于后缀的情况。

思路: nex数组的应用,KMP求出nex组
每次去掉next[i]到i的一段字符,剩余字串仍满足条件
直到找到头为止。

#include<iostream>
#include<stdio.h>
#include<queue>
#include<string.h>
#define clr(p) memset(p,-1,sizeof(p))
using namespace std;
priority_queue<int> ans;
int nex[400005];
string s;
int len;
void get_nex()
{
    int j=-1;
    nex[0]=-1;
    for(int i=0;i<len;i++)
    {
        while(j!=-1&&s[j+1]!=s[i])
        j=nex[j];
        if(s[i]==s[j+1]&&i!=0)
        j++;
        nex[i]=j;
    }
}
int main()
{
    while(cin>>s)
    {
        len=s.size();
        get_nex();
        int j=nex[len-1];
        ans.push(-len);
        while(j!=-1)
        {       
            ans.push(-j-1);
            j=nex[j];   
        }
        while(!ans.empty())
        {
            printf("%d ",-ans.top());
            ans.pop();
        }
        cout<<endl;
    }   
}
Python 爬虫实战:医学临床指南爬取(含 PDF 解析与结构化存储) 在当今数字化时代,医学临床指南作为医生进行科学诊疗的重要参考资料,包含大量经过临床验证的诊疗路径和建议。这些指南通常发布在权威医学网站上,数量庞大且更新频繁。如何自动化地抓取并存储这些指南,成为医疗数据分析、医学研究以及医疗 AI 模型训练等工作的关键第一步。本文将系统讲解如何利用 Python 爬虫技术从权威医学网站爬取临床指南内容,并实现 PDF 解析与结构化存储。 阅读详情

相关推荐

MS1826A HDMI 多功能视频处理器 HDMI4进1出画面分割芯片

基本介绍 MS1826A 是一款多功能视频处理器,包含 4 路独立 HDMI 音视频输入通道、1 路 HDMI 音视 频输出通道以及 1 路独立可配置为输入或者输出的 SPDIF、I2S 音频信号。支持 4 个独立的字库定 制型 OSD;可处理隔行和逐行视频或者图形输入信号;有四路独立视频播放引擎可支持视频多路 播放。该产品提供了高质量的视频输出,有解隔行输入、视频增强,以及帧率转换的处理能力。 功能特征 视频输入输出  四路独立 HDMI 输入通道  一路 HDMI 输出通道  最高支持 4K@3

qq_45645383的博客 1791

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

weixin_46285832的博客 283

02-Cesium-实现天地图标记

首先天地图申请token,然后Cesium-实现天地图标记详细说明

m0_62785037的博客 1173

U - Seek the Name, Seek the Fame

Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u [Submit]   [Go Back]   [Status] Description

mr_lee 632

VCS的增量和分离编译

vcs的增量和分离编译

yunduor909的博客 3311

SAP系统中PP模块全配置文档

配置路径IMG>SAP NetWeaver>常规设置>维护日历>工厂日历事务代码SCAL要求传输工厂代码描述日历代码日历描述起始日期星期一星期二星期三星期四星期五星期六星期日有效开始日期有效结束日期1000南微医学工厂MT南微医学工厂日历√√√√√√√201820502.4定义工厂配置路径IMG>生产>物料清单>常规数据>定义BOM状态事务代码OS23要求传输配置路径IMG>生产>主数据>资源>常规数据>标准值>定义参数。

yanzibing99的博客 1906

poj——2752 KMP||NEX数组的活用,【经典题】

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

HPU WIN 401

研制过程评审活动(三)工程研制阶段

工程研制阶段主要任务、及评审活动

Abel的博客 2393

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

qq_52011873的博客 297

TC397 EB MCAL开发从0开始系列 之 [13.1] Dma配置实战 -实现M2M数据传输(读存储写存储)

TC3XX TC397 MCAL DMA 从0搭建测试用例-实现M2M 存储到存储数据传输

yy九歌的博客 1929

无人船 | 基于ROS的轻量级多无人艇自主导航仿真框架

无人水面艇USV是海上自主无人系统的关键组成部分,在民用、军用领域应用广泛,例如海上救援、水质测量、扫雷反潜等,因此对USV导航算法的研究具有重要意义。为了便于进行USV相关算法的验证与部署,本文介绍的这套基于ROS的多无人艇的自主导航仿真平台,轻量化地实现了建图、规划、控制等多种功能,同时自研框架保证了功能的高度可拓展和可定制

FRIGIDWINTER的博客 8030

算法基础课第二章KMP

KMP算法用于进行字符串匹配。 暴力的方法是每次失配就从模式串的头部进行匹配,但是因为有前后缀匹配的情况,不必每次回到头部,通过一个next数组, 可以在失配时让主串i去匹配next[j],这样能很快的进行匹配。 如何使用next数组 void KMP(string s, string p) { int j, i = 0; while(i < p.size()) { if(j == -1 || s[j] == p[i])//j == -1 说明第一个字符也不匹配,这样j归0, i增加

csdn_ggboy的博客 262

零基础学写《扫雷》游戏(Qt扫雷源码)

扫雷游戏是在windows系统中自带的游戏,他的游戏玩法其实很简单,20世纪初期电脑上没有啥游戏可以玩,所以扫雷游戏也算是当时是最常火爆的一个电脑游戏。以下文章详细介绍扫雷游戏的实现。实现语言为C++。

啊渊的专栏 1万+

poj 2752 kmp(next数组的应用)

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

楠先生 810

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

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

poj2752 Seek the Name, Seek the Fame--------KMP

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

Shirley 2674

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

poj 2752

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

俱往矣 515

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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 sa

vickey 569

【poj2752】Seek the Name, Seek the Fame KMP

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

DQS的树洞 838

POJ 2752 Seek the Name, Seek the Fame

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

Monster_Day的博客 7826

kmp模板

/* pku3461(Oulipo), hdu1711(Number Sequence) 这个模板 字符串是从0开始的 Next数组是从1开始的 */ #include #include using namespace std; const int N = 1000002; int next[N]; char S[N], T[N]; int slen, tlen; void getNe

西天取经~ 547

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 Description The little cat is so famous, that many couples t...

weixin_33755847的博客 219

Poj 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 names to their newly-born babies. They seek the name, and at the sa

lkbsbird的博客 316

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

POJ 2752+KMP+利用next数组性质求出所有相同的前缀和后缀

题目链接:点击进入 这个题目要求所有相同的前缀和后缀的长度。我们可以利用KMP算法中next数组的性质,在next[len]这个点不断的失配下去,这样就可以将所有相同的前后缀的长度求出来。还要注意这个中整个串的长度也可以看成是一个合法的解。代码如下:#include<iostream> #include<cstdio> #include<cstring> using namespace std;c

荒野孤鹰 1765

HDU 3746 KMP求循环节

Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4356 Accepted Submission(s): 1977Problem Description CC always becomes ver

仰望天空 701

【算法讲解】前缀函数(KMP的next函数)

这里的主要目的是理解KMP算法中next[]数组的含义和实现过程:前缀函数主要是求出模式串中的next数组,那么什么是模式串呢?模式串模式串的概念很简单。举个例子:“给出一个字符串 T,再给出 n 个字符串 S1、S2...Sn,问 S1、S2...Sn 中有哪些是 T 的子串?”在这个例子中,S1、S2...Sn 便是 n 个模式串,T便是被匹配串。模式串是用来与被匹配串匹配的。其实,个人感觉,

Google、在奋斗 3277
上一篇: 【Codeforces 570D 】Tree Requests dfs序+二分
下一篇: 【poj 2185 Milking Grid】 KMP*2
ALPS233
博客等级 码龄11年 25粉丝 191原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值