Theme Section HDU - 4763 (kmp)

银河麒麟V10SP1实战:5步搞定AD域登录(附Samba+Winbind配置详解) 本文提供银河麒麟V10 SP1操作系统无缝集成Windows AD域的实战指南。文章深入解析了Samba、Winbind与Kerberos三大核心组件的协作原理,并详细阐述了从环境准备、软件包安装、配置文件定制到执行加域及排错的全流程。特别针对2403等新版本提供了关键配置差异与避坑要点,旨在帮助企业运维人员实现高效、稳定的域环境登录与管理。 阅读详情

Theme Section

HDU - 4763

It's time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To make the programs more interesting and challenging, the hosts are going to add some constraints to the rhythm of the songs, i.e., each song is required to have a 'theme section'. The theme section shall be played at the beginning, the middle, and the end of each song. More specifically, given a theme section E, the song will be in the format of 'EAEBE', where section A and section B could have arbitrary number of notes. Note that there are 26 types of notes, denoted by lower case letters 'a' - 'z'.

To get well prepared for the festival, the hosts want to know the maximum possible length of the theme section of each song. Can you help us?

Input
The integer N in the first line denotes the total number of songs in the festival. Each of the following N lines consists of one string, indicating the notes of the i-th (1 <= i <= N) song. The length of the string will not exceed 10^6.
Output
There will be N lines in the output, where the i-th line denotes the maximum possible length of the theme section of the i-th song.
Sample Input
5
xy
abc
aaa
aaaaba
aaxoaaaaa
Sample Output
0
0
1
1
2
利用Next数组,这样最长前后缀就得到了,然后只需要用kmp在看一下中间部分是否有这一段字符串就可以了

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 1e6+100;
char s[MAXN];
int Next[MAXN];
void getNext(){
    int i = -1,j = 0;
    int len = strlen(s);
    Next[0] = -1;
    while(j < len){
        if(i == -1 || s[i] == s[j]){
            i++,j++;
            Next[j] = i;
        }
        else
            i = Next[i];
    }
}
bool kmp(int st){
    int i = 0,j = st;
    int n = strlen(s);
    while(j < n-st){
        if(i == -1 || s[i] == s[j])
            i++,j++;
        else
            i = Next[i];
        if(i == st)
            return true;
    }
    return false;

}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int i,j,len,Max = 0;
        scanf("%s",s);
        len = strlen(s);
        if(len < 3){
            printf("0\n");
            continue;
        }
        getNext();
        while(Next[len] != -1){
            if(Next[len] > Max && kmp(Next[len])){
                Max = Next[len];
                break;
            }
            len = Next[len];
        }
        printf("%d\n",Max);
    }
    return 0;
}



OpenCV 实战篇——如何测算出任一副图片中的物体的实际尺寸?传感器尺寸与像元尺寸的关系? 本文介绍了通过相机图像测算物体实际尺寸的方法,重点分析了传感器参数与成像质量的关系。文章首先给出了物体实际尺寸的计算公式,涉及像素尺寸、距离、分辨率等参数。然后详细解析了传感器尺寸与像元尺寸的关系,指出相同分辨率下更大的传感器能获得更好的成像质量。此外还介绍了光学尺寸、像素尺寸对成像的影响,以及帧率的概念。最后提及了相机标定的重要性,并概述了从像素坐标系转换到世界坐标系的基本思路。这些知识为通过相机图像进行精确测量提供了理论基础。 阅读详情

相关推荐

《LabVIEW ZYNQ实战指南》第6章>>案例解析:基于USB WiFi模块的ZYNQ无线通信部署与Linux RT开发

本文详细解析了如何为ZYNQ开发板部署USB WiFi模块,实现无线通信。通过LabVIEW Linux RT环境,利用封装好的驱动VI,开发者可轻松配置ZYNQ连接无线网络,摆脱网线束缚,实现程序无线部署与远程调试,为工业物联网应用奠定基础。

app77的博客 755

Theme Section⭐⭐(kmp!!)题意+思路

It's time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To make the programs more interesting and challenging, the hosts are going to add some constraints to t.

with_wine的博客 289

C# Code-Behind 技术全面解析

Code-Behind 是 ASP.NET Web Forms 中的一种技术模式,通过将用户界面标记(.aspx文件)与程序逻辑代码(.aspx.cs文件)分离,实现表现层与逻辑层的解耦。其核心思想是前端展示与后台逻辑的物理文件分离,通过ASP.NET编译器将两者合并编译成一个Page类并执行。Code-Behind 的优势包括较好的代码组织、较高的开发效率,尤其适合快速开发数据驱动应用。然而,与现代开发模式如ASP.NET MVC、ASP.NET Core和Blazor相比,Code-Behind 在可维

记录学习的过程 956

Theme Section(主题部分)(kmp经典模板题) HDU - 4763

题目:Theme Section(主题部分)中文大意 It’s time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To make the programs more interesting and challenging, the hosts are going to

R_711的博客 332

Halcon窗体开发避坑指南:C#自定义控件实现7大图像交互功能

本文详细介绍了如何利用C#封装自定义Halcon控件,以解决原生HWindowControl功能不足的问题。通过实战代码,展示了如何实现图像按比例显示、鼠标拖动缩放、灰度值读取、图像保存、截图及图形叠加等七大核心交互功能,并重点剖析了内存管理、坐标转换等开发避坑要点,帮助开发者构建稳定可复用的机器视觉组件库。

weixin_29251131的博客 292

Mplus—随机截距交叉滞后模型(Random Intercepts Cross-Lagged Panel Model, RI-CLPM)

介绍随机截距交叉滞后模型(Random Intercepts Cross-Lagged Panel Model, RI-CLPM)的相关知识,例如模型内容、Mplus语法及对应网址等。

m0_54401011的博客 9532

KMP-Theme Section

Description It’s time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To make the programs more interesting and challenging, the hosts are going to add some const

weixin_43856210的博客 146

Python与西门子PLC数据交互实战:基于Snap7的跨平台工业通信指南

本文详细介绍了如何使用Python和Snap7库实现与西门子PLC的数据交互。内容涵盖跨平台环境搭建、连接参数配置、数据读写实战及性能优化技巧,为工业自动化、数据采集和智能制造场景提供了一套轻量、灵活且高效的通信解决方案。

vim8coder的博客 283

【HDU】 4763 Theme Section (KMP)

Theme Section Problem Description It's time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To mak

Silence的程序实验室 1297

学术类PPT制作总结

本文分享了科技类PPT的制作技巧,希望相关的信息能帮助到读者。

奇妙水果的技术博客,欢迎交流技术~ 2881

Open3D——平面点云凸多边形轮廓提取【2025最新版】

平面点云凸多边形轮廓提起,博客长期更新,本文最近更新时间为:2025年1月6日。

点云侠的博客 6753

HDU 4763 字符串的前中后三段公共子串

Description It's time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To make the programs more interes

became_a_wolf的专栏 596

DXF转G代码是圆弧的方向如何确定?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 1186

HDU4763 Theme Section 【KMP】

Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1114    Accepted Submission(s): 579 Problem Description It's time for

长风的专栏 1370

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

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

hdu 4763 Theme Section(KMP)

题目链接:  hdu 4763 题目大意:  找出字符串的最长子串,这个子串满足既是前缀和后缀,并且在中间会出现 解题思路:  不妨先找出所有前缀等于后缀的子串长度(poj 2752 解题报告)                    从长到短(长度不大于主串的1/3)枚举子串的长度                   前缀等于后缀的子串长度为ans[ i ]            

ンZee的解题报告 1216

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

HDU4763 Theme Section(KMP)

题目链接:hdu4763 题面 题目大意 找到字符串中的最长公共前后缀,并且这个前后缀的字串在除了前后缀的中间部分也要存在这个子串。例如:EAEBE,其中,E 表示这个子串,输出 E 的最大长度,如果不存在输出 0 。 解题思路 KMP 利用求失配函数得到串的最长公共前后缀,然后从 2i 的位置到 len-i 的位置开始枚举中间是否存在子串,判断条件是: fail[j]==ifail[j]==ifail[j]==i。含义是失配指针能够索引到公共前缀后一个位置,然后从 j 位置到达 i 表示 0 - j

小胡同的诗 304

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Hdu 4763 Theme Section KMP

Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3667    Accepted Submission(s): 1721 Problem Description It's time fo

J. Cole 441

HDU4763 Theme Section KMP

HDU4763 Theme Section KMP 字符串满足EAEBE,E为相同的前后缀,只需在中间找出另一个E即可 利用nxt数组的性质,找出E即可 /*KMP字符串匹配 next[i]记录1~i中相同前后缀长度-1 即相同字符下标位置 171MS 6108K */ #include &lt;stdio.h&gt; #include &lt;string.h&gt; const int...

Qianyri的博客 323

HDU 4763 Theme Section(KMP)

【链接】http://acm.hdu.edu.cn/showproblem.php?pid=4763 【题意】给个字符串,求满足形如“E...E...E”这种鬼样子的E串最大长度,其中“...”可以是任意个数的任意字符(没有也ok),但是三个E之间不能重叠 【思路】 无视中间那个“E”的话,其实是在求前后缀相同的最大缀长 回头看一眼刚刚写完的poj 2752,终于知道为什么搜题解的

无色城 956

hdu4763 Theme Section KMP

给一个字符串S,问是否存在一个子串s'同时为s的前缀,后缀,并且至少出现在前缀后缀之外的位置一次(互不重叠)。10^6的数据...一开始想写后缀数组,看这数据估计是要卡倍增,DC3又没写过..后来想了想直接KMP扫一遍好像就行..以末尾为起点,遍历从失配路径上的每一个点,如果f[j]小于len/3,那么就从2*f[j]+1~len-f[len] 之间枚举k看是否存在f[k]==f[j],存在的话答

Broken Wings 736

HDU 4763 Theme Section(KMP)

题目链接:点击打开链接 题意:给你一个字符串s, 要你求是否存在一个子串, 在s的前中后各出现一次。 求最大可能的子串长度。 思路:KMP变形, 我们首先要了解KMP的运行机制。  核心是失配函数f, f[i]表示在i点失配之后返回到f[i]这个点, 且能保证f[i]之前的部分和模板串匹配。  这样的话, 我们就可以利用这个特点来处理该题了。 我们假设在最后一个字符处失配, 那么它将返回f[l

AC_Arthur的专栏 1189

Theme Section HDU - 4763(kmp )

Theme Section HDU - 4763 题意: 给你一个字符串s。 要求你找到最长的前缀&&中缀&&后缀。 思路: 可以对串s求next 假如nxt【len】x 3 >len.(那么说明太长了,要缩短) 可以len=nxt【len】。 之后贪心的找就可以了。把s按照长度next【len】切割成 三部分。 (nxt【len】+(len-nxt【len】-nxt【len】)+nxt【len】) 对长度为nxt【len】的字符串,再求一次next2. 把它与中间

qq_45377553的博客 163

hdu 4763 Theme Section kmp

这个next[i]表示的就是最长前后缀,那么头和尾的就不next就可以得出了 那么就剩下判断中间是否存在了,中间的只要不重叠的那部分存在一个next[j]大于的就可以了。 中间的部分是不断扩大的,那么就头尾不断next,中间不断更新新加入的节点即可。 #include #include #include using namespace std; const int maxn=1e6+9

yrleep的专栏 1060

hdu 4763 Theme Section (扩展kmp)

hdu 4763 Theme Section (扩展kmp) 题目大意:给出一个字符串,问这个字符串的最长Theme Section是多长,Theme Section要符合以下条件,必须出现在字符串的开头,结尾,和中间,而且不能有重叠。 很抱歉,之前写了个很挫o(nlogn)的解法,误导了大家,后来我仔细想了想,其实用扩展kmp可以o(n)的实现。下面给出具体的实现方法: 解题思路:还是

No__stop 2183

扩展kmp -- Theme Section HDU - 4763

Theme Section HDU - 4763 题意: T次询问,每次给你一个字符串s(|s| <= 1e6),找到一个最长的子串,出现在s的串首、串中、串尾位置,互不重叠。输出这个子串的长度。 思路: 先用扩展kmp处理出s每位s[i]开头的的子串与前缀的最大长度,保存在nxt数组中,从尾部开始遍历nxt数组,如果i + nxt[i] = |s|(s的长度),则说明检索出了串首、串尾的两个子串,那再检索串中的子串是否存在,并在检索的过程中保证串首、串中、串尾的子串互不重叠。 code: #incl

dajiangyou123456的博客 342

HDU 4763 Theme Section(kmp)

Time Limit:1000MS Memory Limit:32768KBDescription It’s time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative s

2cm的专栏 377
上一篇: 最长回文 HDU - 3068 (Manacher算法)
下一篇: Phone List POJ - 3630 (字典树或string)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值