Simpsons’ Hidden Talents HDU - 2594 (KMP)

riemann geometry pdg格式,需用超星阅读器阅读 专门、独到、详实、经典 立即下载

Simpsons’ Hidden Talents

HDU - 2594


Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had.
Marge: Yeah, what is it?
Homer: Take me for example. I want to find out if I have a talent in politics, OK?
Marge: OK.
Homer: So I take some politician’s name, say Clinton, and try to find the length of the longest prefix
in Clinton’s name that is a suffix in my name. That’s how close I am to being a politician like Clinton
Marge: Why on earth choose the longest prefix that is a suffix???
Homer: Well, our talents are deeply hidden within ourselves, Marge.
Marge: So how close are you?
Homer: 0!
Marge: I’m not surprised.
Homer: But you know, you must have some real math talent hidden deep in you.
Marge: How come?
Homer: Riemann and Marjorie gives 3!!!
Marge: Who the heck is Riemann?
Homer: Never mind.
Write a program that, when given strings s1 and s2, finds the longest prefix of s1 that is a suffix of s2.

Input
Input consists of two lines. The first line contains s1 and the second line contains s2. You may assume all letters are in lowercase.
Output
Output consists of a single line that contains the longest string that is a prefix of s1 and a suffix of s2, followed by the length of that prefix. If the longest such string is the empty string, then the output should be 0.
The lengths of s1 and s2 will be at most 50000.
Sample Input
clinton
homer
riemann
marjorie
Sample Output
0
rie 3
直接以s1为模板串,以s2为目标串进行kmp匹配,直到结束,就是s2的后缀和s1的前缀的共同最长长度

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 50010;
int Next[MAXN];
char s1[MAXN],s2[MAXN];
void getNext(){
    int i = -1,j = 0;
    int len = strlen(s1);
    memset(Next,0,sizeof(Next));
    Next[0] = -1;
    while(j < len){
        if(i == -1 || s1[i] == s1[j]){
            i++,j++;
            Next[j] = i;
        }
        else
            i = Next[i];
    }
}
int kmp(){
    int i = 0,j = 0;
    int lens1 = strlen(s1);
    int lens2 = strlen(s2);
    getNext();
    while(j < lens2){
        if(i == -1 || s1[i] == s2[j])
            i++,j++;
        else
            i = Next[i];
    }
    return i;
}
int main(){
    while(~scanf("%s%s",s1,s2)){
        int n = kmp();
        int i;
        if(n==0) printf("0\n");
        else{
            for(i = 0; i < n; i++)
                printf("%c",s1[i]);
            printf(" %d\n",n);
        }

    }
    return 0;
}


简单的图书管理系统---SpringBoot+mysql通过前后端分离实现增删查改 SpringBoot+mysql通过前后端分离实现增删查改 上篇文章介绍了如何写后端接口 SpringBoot连接MySQL获取数据写后端接口 这篇文章,我们就介绍一下怎么写前端 点击修改跳出修改界面,点击添加书籍跳出添加书籍界面 点击删除,直接删除一行数据 其他的也没什么解释了,直接上代码(看不懂的可以私聊我哟) <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> 阅读详情

相关推荐

别再乱按F8了!Win10系统修复的正确姿势:用管理员CMD运行sfc /scannow

本文详细介绍了Windows 10系统修复的正确方法,重点推荐使用管理员CMD运行`sfc /scannow`命令。相比传统的F8键和重装系统,这一方法更高效且安全,能解决大多数系统文件损坏问题。文章还提供了管理员CMD的启动方式、sfc命令的完整参数解析以及实战故障排除流程图,帮助用户快速恢复系统健康。

weixin_29218963的博客 457

Simpsons’ Hidden Talents(辛普森一家的隐藏天赋 )(kmp经典模板题) HDU - 2594

题目:Simpsons’ Hidden Talents(辛普森一家的隐藏天赋 )中文大意 Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marge: Yeah, what is it? Homer: Take me for example. I want to find out if I have a talent in politics, OK? Marge:

R_711的博客 525

本地部署 Bolt.new - 小学生都能轻松搭建AI编程环境

本地部署 Bolt.new - 小学生都能轻松搭建AI编程环境

engchina的专栏 8623

Simpsons’ Hidden Talents (kmp运行题)

【题目来源】:https://vjudge.net/problem/HDU-2594 【题意】 求第一个字符串的前缀和第二个字符串的后缀的字符最大匹配量。 如: riemann marjorie 得:rie 字符数量是3、 【思路】 起初以为这道题依旧是有关于next数组的题,然后就有了一系列的代码应运而生。自己试的样例都过了,wrong的一塌糊涂。 额,初学者的我只知道kmp

Crazy 574

Keil AC6编译器独立安装与配置指南:不升级Keil MDK也能用上新工具链

本文详细介绍了如何在不升级Keil MDK的情况下独立安装和配置Arm Compiler 6(AC6),帮助嵌入式开发者充分利用AC6的编译速度、代码密度和现代语言支持优势。通过零侵入式解决方案,开发者可以在现有环境中灵活切换编译器版本,提升开发效率。

weixin_30872157的博客 552

SICK LMS111激光雷达数据解析实战:从原始帧到三维点云的完整流程

本文详细解析了SICK LMS111激光雷达从原始数据帧到三维点云的完整处理流程,包括数据帧结构解析、坐标转换、点云可视化及性能优化技巧。通过实战代码示例,展示了如何高效处理激光雷达数据,并应用于动态物体检测、地面分割等工业场景,为AGV和服务机器人开发者提供实用指南。

garlic的博客 767

【 HDU - 2594 】Simpsons’ Hidden Talents(KMP应用,求最长前缀后缀公共子串)

题干: Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had.  Marge: Yeah, what is it?  Homer: Take me for example. I want to find out if I have a talent in pol...

xuanweiace的博客 600

国科大——形式语言与自动机理论(0812课程)——作业

此次作业题考察,包括但不限于有限自动机、无限自动机、正则文法、正则表达式以及正则语言的性质,题考查下推自动机相关的知识,题考查图灵机相关的知识。此课程建议本科学习过课程的同学选修,成绩占比:考试100%。此课程虽然留有作业,但可做也可不做,且不考勤。

qq_54145399的博客 705

Simpsons’ Hidden Talents

Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6687 Accepted Submission(s): 2396Problem Description Homer: Marge

wo的只属于我 1886

运动想象 (MI) 分类学习系列 (19) : EEG-TransNet

本文提出了一种基于注意力机制的卷积神经网络(EEG-TransNet),用于运动想象脑电图(MI-EEG)解码。该方法创新性地通过平均池化和方差池化提取多模态时间信息,并结合自注意力模块捕获长期依赖关系。消融实验表明,方差池化比最大池化更有效(p<0.05),且注意力模块和卷积编码器对特征判别性至关重要。可视化分析验证了该方法能学习到更具判别性的紧凑特征。该工作为MI-EEG解码提供了新的多尺度时间信息融合视角,代码已开源。

走在深度学习前沿的小宋 358

QGis软件 —— 1、Windows10下载安装QGis及插件

QGis —— 1、Windows10下载安装QGis及插件

5157

【KMP】 hdu2594 Simpsons’ Hidden Talents

Simpsons’ Hidden Talents http://acm.hdu.edu.cn/showproblem.php?pid=2594 Problem Description Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had.

Ted's 游乐园 1430

LeetCode 面试经典 150 题回顾

最经典 150 题,掌握面试所有知识点 面试经典 150 题 : 题目分析、解题思路、复杂度分析、代码展示

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 8万+

【hdu2594】Simpsons’ Hidden Talents——KMP

题目: Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5599    Accepted Submission(s): 2025 Problem Descripti

CFhM_R's Blog 447

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

HDU 2594 Simpsons’ Hidden Talents kmp

一、内容 Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marge: Yeah, what is it? Homer: Take me for example. I want to find out if I have a talent in poli...

Tizzi的博客 943

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

HDU2594 Simpsons’ Hidden Talents 【KMP】

Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2798    Accepted Submission(s): 1055 Problem Description H

长风的专栏 1077

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

hdu 2594 Simpsons’ Hidden Talents(KMP)

Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2181    Accepted Submission(s): 818 Problem Description Ho

街角的花街糖 1567

HDU 2594 Simpsons’ Hidden Talents KMP

题目: Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marge: Yeah, what is it? Homer: Take me for example. I want to find out if I have a talent in polit...

zamaochick的博客 221

hdu 2594 Simpsons’ Hidden Talents【kmp】

Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10278    Accepted Submission(s): 3579 Problem Description

loving coding 289

【题解】Simpsons’ Hidden Talents HDU - 2594⭐⭐ 【扩展KMP】

Simpsons’ Hidden Talents HDU - 2594 求S1的前缀和S2的后缀的《最大》匹配 Input 多组输入,第一行S1,第二行S2。 S1和S2的长度小于50000。 Output 输出一行。 如果没有匹配,那么只输出一个0。 反之,输出匹配的字符串和匹配长度。中间一个空格间隔。 Examples Sample Input clinton homer riemann ...

Suprit's blog 634

HDU 2594 Simpsons’ Hidden Talents (KMP)

KMP

NeWnIx 536

HDU2594 Simpsons’ Hidden Talents 拓展KMP

HDU2594 Simpsons’ Hidden Talents nxt[ i ]表示s1[ i ~ m - 1 ] 与s1[ 0 ~ m - 1 ]的最长公共前缀 extend[ i ]表示s2[ i ~ n - 1 ] 与s1[ 0 ~ m - 1 ]的最长公共前缀 求最长的  s1的前缀==s2的后缀  即 #include&lt;bits/stdc++.h&gt; using n...

Qianyri的博客 304

kuangbin专题十六 KMP&&扩展KMP HDU2594 Simpsons’ Hidden Talents

kuangbin专题十六 KMP&amp;&amp;扩展KMP HDU2594 Simpsons’ Hidden Talents Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marge: Yeah, ...

ACMerszl的博客 236

HDU 2594 Simpsons’ Hidden Talents(KMP)

题意:给定两个字符串s1,s2,求最长的s1前缀ss使得ss为s2的最长后缀,输出该字符串和其长度。 做法1:将两个字符串首位相接,直接利用next数组性质得出答案 #include #include #include #include #include #include #include #include #include #include #include #incl

Ezereal的博客 566

HDU 2594 Simpsons’ Hidden Talents(kmp)

Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marge: Yeah, what is it? Homer: Take me for example. I want to find out if I have a talent in politics, ...

起名好难呀! 124

hdu2594 Simpsons’ Hidden Talents(KMP)

Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7787    Accepted Submission(s): 2755 Problem Description H

Renl1000的博客 364
上一篇: How many HDU - 2609 (最小表示法)
下一篇: Traveling
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值