hdu 2594 Simpsons’ Hidden Talents【kmp】

狗都能看懂的MAML原理讲解和代码实现 meta-leaning指的是元学习,元学习是深度学习的一个分支,一个好的元模型(meta-learner)应该具备对新的、少量的数据做出快速而准确的学习。通俗的来讲, 对于人来说,给几张橘猫的图片让看一下,再给你几张没见过的英短猫图片,你一定能很快识别出来都是猫。但是对于神经网络来说,并非如此。如果让一个小汽车分类网络去识别不同的大货车,那效果肯定很差。而传统的CNN网络都是输入大量的数据,然后进行分类的学习。但是这样做的问题就是,神经网络的通用性太差了,根本达不到“智能”的标准。而人类的认知系统,可以通 阅读详情

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

Source
 

题意:读入串1和串2,输出串2的前缀和串1的后缀最长公共部分和长度。

思路:将串1作为子串s2,串2作为主串s1,套用kmp.

#include<stdio.h>
#include<string.h>
#define N 50010
char s1[N],s2[N];
int next[N],l1,l2;

void get_next()
{
    int j,k;
    j = 0;
    next[0] = k = -1;
    while(j < l2)
    {
        if(k==-1||s2[j]==s2[k])
            next[++j] = ++k;
        else
            k = next[k];
    }
    return;
}
void kmp()
{
    int i,j,k;
    i = j = 0;
    while(i < l1)
    {
        if(j == -1||s1[i]==s2[j])
        {
            i++;
            j++;
        }
        else
            j = next[j];
    }
    if(!j)//当s1的后缀和s2前缀不匹配时 
        printf("0\n");
    else
    {
        for(k = 0; k < j; k ++)//j是能匹配到s2前缀的长度 
            printf("%c",s2[k]);
        printf(" %d\n",j);
    }
    return;
}

int main()
{
    while(scanf("%s %s",s2,s1)!=EOF)
    {//读入时,将第二行字符串作为主串,第一行字符作为子串 
        l1 = strlen(s1);
        l2 = strlen(s2);
        get_next();//建立next数组 
        kmp();//字符串前后缀匹配 
    }
    return 0;
}

【实战指南】RF-DETR目标检测全流程:从数据准备到工业部署 本文详细介绍了RF-DETR目标检测模型的全流程应用,从数据准备、模型训练到工业部署。RF-DETR作为基于Transformer的先进模型,在COCO基准测试中表现优异,推理速度超越YOLOv8,特别适合工业场景。文章还提供了数据标注、COCO格式转换、超参数调优及边缘设备部署的实用技巧,帮助开发者高效实现目标检测任务。 阅读详情

相关推荐

CST中PEC结构涂覆吸波材料的RCS仿真与优化

本文详细介绍了在CST Studio Suite中对PEC结构涂覆吸波材料进行RCS仿真的完整流程与优化策略。通过精确的材料参数设置、涂层厚度优化和仿真技巧,有效降低目标的雷达散射截面,提升隐身性能。文章结合实战案例,为工程师提供了一套高效的RCS仿真与优化解决方案。

c2d3e4f的博客 709

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

OpenCV图像拼接实战:用SIFT+透视变换打造无缝全景图(附完整代码)

本文详细介绍了使用OpenCV和SIFT算法实现图像拼接的全过程,包括特征匹配、透视变换和高级融合技术。通过实战代码演示,帮助开发者掌握无缝全景图生成的核心技术,适用于旅行摄影、无人机航拍等多种场景。

eee77的博客 1011

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的博客 946

radsystems的激活(破解)和使用

上个文章讲述了radsystems的下载,但是只有30天的免费使用权,这篇文章将会讲解如何破解激活radsystems。注意:如果不想去官网下载的话,点击安装包的exe文件。不要急,打开我给你们的安装包,点击crack。如果提示done则完成(我的是激活过的)注意:这是8.7版本的。点击generate。

weixin_65144487的博客 3602

ARFoundation系列讲解-教程目录

一、教程目录 ARFoundation快速入门-01简介 ARFoundation快速入门-02环境搭建 ARFoundation快速入门-03环境配置之iOS ARFoundation快速入门-04环境配置之Android ARFoundation快速入门-05ARKit设备支持列表 ARFoundation快速入门-06ARCore设备支持列表 ARFoundation快速入门-07检查设备支持 ARFoundation快速入门-08平面检..........

a451319296的博客 3万+

【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 游乐园 1432

2023华为od机试【最小循环子数组】C++

2023华为od机试【最小循环子数组】C++ 给定一个由若干整数组成的数组nums,请检查数组是否是由某个子数组重复循环拼接而成,请输出这个最小的子数组。

MISAYAONE的博客 2191

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

PCL:实现 PPF估计(附完整源码)

PCL:实现 PPF估计(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 737

解锁PyCharm+Deepseek:本地部署AI编程超能力

在本次探索中,我们成功地在 PyCharm 中实现了 DeepSeek 的本地化部署,这一过程虽然涉及多个步骤,但每一步都为我们开启 AI 编程大门奠定了基础。从安装最新版 PyCharm,确保我们拥有一个功能强大且兼容性良好的开发环境,到注册 DeepSeek 账号并获取 API Key,这是连接我们与强大 AI 能力的关键纽带。接着,在 PyCharm 中安装 Continue 插件并进行精细配置,让 DeepSeek 能够深度融入我们的编程流程。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 5557

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

Devexpress16.2.6破解工具

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

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

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

【题解】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 636

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

HDU 2594 Simpsons’ Hidden Talents (KMP)

KMP

NeWnIx 536

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的博客 240

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的博客 309

HDU 2594 Simpsons’ Hidden Talents KMP

传送门http://acm.hdu.edu.cn/showproblem.php?pid=2594 题目要求的是求第一个字符串的前缀是第二个字符串的后缀。 我还以为是第一个字符串在第二个字符串出现,不用后缀。。。。。。 WA了一次。。 看题要仔细。。。。 根据KMP 字符查找过程中,会有一个状态值j,这个j表示s2已经匹配了s1多少个字符。所以当全部匹配完之后,j即

细语呢喃 997

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的博客 366

HDU 2594 Simpsons’ Hidden Talents(KMP)

解题思路: 求相同的前缀和后缀。开一个数组保存到i位置,模式串有多少个字符和文本串匹配即可。 #include #include #include #include #include #include #include #include #include #define LL long long #define FOR(i,x,y) for(int i=x;i<=y;i++)

蘑菇--走在通往梦想的道路上。 694

HDU2594 Simpsons’ Hidden Talents(KMP)

给两个字符串,找到两个字符串的最长相同后缀和前缀。 KMP,把两个字符串连接起来,最后一个字符的next数组内容就是最长的长度。 两个字符串之间要插入一个其他字符。 #include #include #include #include using namespace std; const int N=50005; char str1[N]; char str2[N],str[N*1

HOrchard 283

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的博客 569

Simpsons’ Hidden Talents HDU - 2594 (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 politic...

Top_Spirit的博客 217

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

起名好难呀! 125

HDU2594 Simpsons’ Hidden Talents【KMP】

题目大意: 给你两个串S1和S2,求既是S1的前缀同时是S2的后缀的最长字符串及长度。 思路: KMP算法中Next[j] == k的实质是当前字母不匹配时,模式串的前k项(S0~Sk-1)和位置j前 的k项(Sj-1-k~Sj-1)是相等的,这个k值是所有满足上面情况最大的。那么Next[len]的含义 就是模式串的最长的前缀和后缀相等的串长度。 利用Next[]的性质,先将串S2连接到S1后边。求S1的Next[]数组。那么,现在的Next[len] 就是S1的前缀和S2的后缀最长的长度,这是当这个长

程序员充电站(itcharge) 1015

HDU2594 Simpsons’ Hidden Talents KMP

题目大意:给出两个字符串s1,s2,长度小于50000,让找出s1最长的前缀,同时该前缀又是s2的后缀,如果存在,输出该前缀和前缀的长度。 分析:我们把s1和s2合成一个字符串,求出该模式串的next数组,如果next[ len ]不为0(len为合成的字符串的长度),则即为所求。 实现代码如下: #include #include #include #include

AC_Gibson的专栏 458
上一篇: hdu 1864 最大报销额【01背包变形~】(实数转整型)
下一篇: hdu 2680 Choose the best route【dijstra+反向建图】
努力过
博客等级 码龄10年 93粉丝 295原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值