hdu1841 Find the Shortest Common Superstring

RV1126上YOLOv8部署实战:从模型转换到板端推理的完整避坑指南 本文提供了在瑞芯微RV1126芯片上部署YOLOv8目标识别算法的完整实战指南。内容涵盖从模型转换、环境搭建到板端推理代码编写的全流程,重点解析了RKNN-Toolkit使用、量化配置、内存优化及后处理实现等关键环节的常见问题与解决方案,旨在帮助开发者高效避坑,实现边缘AI应用的稳定落地。 阅读详情

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1841


题解:1.s1是s2的子串,或者s2是s1的子串。2.s1是s2的前缀或者后缀。



#include <stdio.h>    
#include <string.h>    
#define MAXN 1000002   
    
int next[MAXN];    
char str1[MAXN],str2[MAXN];    

void getNext(char *str,int len)    
{    
    int i=0,j=-1;     
    next[0]=-1;    
    while(i<len)    
    {    
        if (j==-1||str[i]==str[j])    
        {    
            i++;    
            j++;    
            next[i]=j;    
        }    
        else    
            j=next[j];    
    }    
}    
    
int KMP(char *str,char *pattern,int len1,int len2)    
{    
    int i,j;    
    i=j=0;
	getNext(pattern,len2);
    while(i<len1&&j<len2)    
    {    
        if(j==-1||str[i]==pattern[j])    
        {    
            i++;    
            j++;   
        }    
        else    
            j=next[j];  
    }    
	if(j<=len2) 
		return j;
	else
		return -1;
}    
  
int main()  
{  
    int test,x,y,len1,len2;  
    scanf("%d",&test);  
    while (test--)  
    {  
		scanf("%s %s",str1,str2);
		len1=strlen(str1);
		len2=strlen(str2);
		x=KMP(str1,str2,len1,len2);
		y=KMP(str2,str1,len2,len1);
		if(x>y)
			printf("%d\n",len1+len2-x);
		else
			printf("%d\n",len1+len2-y);
    }  
    return 0;  
}  




        
ROS2入门到精通—— 1-1 Linux和ROS2基础 本文介绍了Linux的一般指令以及ROS2的常见理论和操作 阅读详情

相关推荐

基于MySQL的京东用户行为分析

对京东用户行为的分析,利用AARRR模型进行分析。

SelenaSelena的博客 1923

HDU - 1841 Find the Shortest Common Superstring

Find the Shortest Common Superstring The shortest common superstring of 2 strings S 1 and S 2 is a string S with the minimum number of characters which contains both S 1 and S 2 as a sequence of

什么样的小孩 的博客 333

立创开源:基于STM32F407的大疆M30T无人机PSDK机载开发板硬件设计与飞行控制实现

本文详细介绍了基于STM32F407微控制器为大疆M30T无人机设计PSDK机载开发板的完整流程。从关键的E-Port接口电路设计、电源保护,到STM32最小系统搭建,再到通过PSDK实现与无人机的通信及基础飞行控制,提供了从硬件到软件的全栈实战指南,助力开发者快速入门无人机负载开发。

weixin_35649491的博客 417

Find the Shortest Common Superstring(hdu1841,KMP)

http://acm.hdu.edu.cn/showproblem.php?pid=1841 解析: 题意: 找到一个最短的串s,含有子串s1,s2 思路:两次KMP匹配 求出,s1后缀和s2前缀的最长公共串长度m1,       s2后缀和s1前缀的最长公共串长度m2;       ans=strlen(s1)+strlen(s2)-max(m1,m2); 6096 KB 359

JHC23的专栏 950

UG NX二次开发(C#)-读取PMI对象的名称

摘要:本文介绍了在UG NX中通过NXOpen获取PMI对象名称的方法。首先说明PMI对象初始无名称,可通过重命名或属性设置名称。然后提供C#代码示例,展示如何遍历PMI集合获取对象名称,并显示名称和类型信息。适用于需要操作PMI对象的开发人员,欢迎加入技术交流QQ群749492565。(99字)

GimiGimmy 608

建模simulink - 手把手教你搭建xpc平台

概述xpc半实物仿真目标是个基于RTW对低端实时仿真和开发平台,可将计算机或者工控机转变为一个实时系统,不需要第三方操作系统对支持,在计算机上配置输入输入出设备就能和外部交换信息,进行硬件...

不只会拍照的程序猿 7094

hdu 1841 Find the Shortest Common Superstring

hdu 1841 点击打开链接 题意:给出两个字符串s1,s2,找到一个最短的字符串s,似的s1是它的子串,s2也是它的字串。 方法:用KMP,首先判断s1是否是s2的字串,若是,则直接输出s2的长度,,即s2就是我们找的s字符串。同理判断s2是否是s1 的字串。 若都不是,,则判断s1 的前缀与s2的后缀最大重合部分k1,s2的前缀与s1后缀最大重合部分k2,判断k1与k2的大小,

ACM_korun 884

自适应滤波-----LMS(Least Mean Square)算法

自适应滤波的意义所在 自适应滤波器解决非平稳的过程,因为实际信号的统计特性可能是非平稳的或者是未知的。 自适应滤波器的特点: 1.没有关于待提取信息的先验统计知识 2.直接利用观测数据依据某种判据在观测过程中不断递归更新 3.最优化 自适应滤波分类: 处理器的结构划分:横向结构、格型结构 重复一次计算自适应需要的数据划分:成批处理法、递归处理法 按调节算法...

heda3的博客 10万+

HDU 1841 Find the Shortest Common Superstring KMP

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1841 题意:给你两个字符串,求解一个最短的字符串,两个字符串连接的时候相同的可以重叠 例如: “alba” 和“bacau”重叠在一起的最短串是 “albacau”。 我感觉这道题用KMP,求next数组就行,先将两个字符串连接起来(两种方法),然后求解next[len],当这个

lamborghini1993 1243

Python爬虫实战:58同城租房信息分析与可视化,寻找高性价比房源

随着城市化进程加快,租房需求日益增长。58同城作为国内领先的本地生活服务平台,汇聚了大量房源信息。本教程将使用最新的Python爬虫技术获取58同城租房数据,通过数据分析与可视化揭示各区域租金水平,并运用机器学习算法找出性价比高的房源。本项目将使用异步爬虫、反爬对抗技术、数据清洗、可视化分析和机器学习建模等技术栈。

2201_76125261的博客 1286

【AI编程】Codex 进阶与高阶技巧:从熟练到精通——2026 最新教程

Skill 是 Codex 的「插件」—— 一段 Markdown 定义触发条件、输入参数和执行流程。比自定义命令更强大,支持参数化、多步骤、条件判断。

十年老程序猿,AI 疯狂研究专家,前沿硬核知识分享 212

hdu1841Find the Shortest Common Superstring

Find the Shortest Common SuperstringTime Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2062    Accepted Submission(s): 570Problem DescriptionThe sh...

mayuqing98的博客 428

手把手教你用LabelImg打造专属YOLO数据集:从标注到训练全攻略!

YOLO(You Only Look Once)是一种快速、高效的目标检测算法。它使用一种简洁的.txt文件格式来保存每张图片中的标注信息,适合构建自定义目标检测数据集。🔹 图像文件.jpg.png等;每张图片将对应一个同名的标签文件(.txtdog.jpg对应dog.txt;图像在训练前通常会被缩放成统一尺寸,例如 YOLOv3 默认输入为416x416。🔹 标签文件(.txt)是一个纯文本文件;每一行表示一个标注目标;字段说明类别编号,从0开始,例如:狗是0,猫是1x_center。

FJN110的博客 2475

hdu1841 Find the Shortest Common Superstring 两遍KMP

hdu1841 Find the Shortest Common Superstring 两遍KMP问题描述 :The shortest common superstring of 2 strings S1 and S2 is a string S with the minimum number of characters which contains both S1 and S2 as a seq

愿赌服输 704

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

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

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

HDU 1841 Find the Shortest Common Superstring

戳这里

WSMYE的博客 (hemiaomiao.me) 316

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

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

HDU 1841: Find the Shortest Common Superstring

!!!#include #include #include using namespace std; char a[2000005],b[2000005]; int nextd[2000010]; void get(char *ch) { int l = strlen(ch); int s = 0,t = -1; nextd[0] = -1; while(s <l) { if(t

无知的博客 609

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

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

hdu 1841 Find the Shortest Common Superstring

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1841 本题的意思就是给出两个字符串,看一下能组成最短的串的长度,当然只能首尾连接 这题也是对KMP的应用,主要还是对next数组的的求解 这题大概应该有两个地方需要注意的 1.开始写这题我直接就把串连接为S=S1+S2和S=S2+S1这两种情况,然后比较取S串最短的那种 比如样例中alba和b...

weixin_30952103的博客 77

hdu1841 Find the Shortest Common Superstring-----KMP

Find the Shortest Common Superstring Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 971 Accepted Submission(s): 243 Problem Description T

Shirley 1430

hdu 1841 Find the Shortest Common Superstring

Find the Shortest Common Superstring Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1222Accepted Submission(s): 320 Problem Description ...

weixin_30378623的博客 87

HDU 1841 Find the Shortest Common Superstring(KMP)

Find the Shortest Common Superstring Problem Description The shortest common superstring of 2 strings S1 and S2 is a string S with the minimum number of characters which contains both S1 and S2 as

持之以恒 471

HDU1841 Find the Shortest Common Superstring(两次KMP)

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1841 题意: 两个字符串拼接,问拼成新串的最小长度,使得新串包含两个原串。 思路: 跑两遍kmp,找最长前缀。(先排除包含情况) #include &lt;bits/stdc++.h&gt; using namespace std; const int maxn = 1e6+10; int...

刘二狗的博客 395

HDU 1841 Find the Shortest Common Superstring(KMP灵活运用)

ind the Shortest Common Superstring Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1149    Accepted Submission(s): 289 Problem Descri

布生气 1368

HDU - 1841 Find the Shortest Common Superstring KMP模板

Find the Shortest Common Superstring Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 2126    Accepted Submission(s): 585 Problem Descr

DlPF_C的博客 303

HDU1841 Find the Shortest Common Superstring (KMP两字符串的首尾连接)

题意:给我们两个字符串,求解一个最短的字符串,两个字符串连接的时候相同的可以 重叠,例如:“alba” 和“bacau”重叠在一起的最短串是 “albacau”。 解析:最初看到这题时,是将两个串连接起来,用strcat函数,然后利用kmp求它的 循环子段,这就是我的数组为啥开的两倍,但后来发现对于“abaa”“a”或者“aaaba” “aa”….类似这一类,它的处理就会出错,后来将它分开处

天行健的博客 463

HDU-1841-Find the Shortest Common Superstring(kmp)

博主CSDN 题目链接 题意: 给出两个串,用这两个串组成一个新串,使新串包含这两个串,问这个新串的长度最小是多少; 题解: 显然,对于两个串A,B;A如果是B的子串或者B如果是A的子串的话,直接输出那个母串的长度即可,如果没有这种关系,那么看一个串的后缀是否是另一个串的前缀,如果某个串的后缀与另一个串的前缀的公共部分最长,则答案=A.length+B.length-公共长度,所以可以直接用km...

Anoyer的博客 378

文章标题 HDU 1841:Find the Shortest Common Superstring(KMP)

Find the Shortest Common SuperstringDescriptionThe shortest common superstring of 2 strings S 1 and S 2 is a string S with the minimum number of characters which contains both S 1 and S 2 as a sequence

Wang_SF2015的博客 469
上一篇: hdu1848 Fibonacci again and again (博弈SG值)
下一篇: hdu2594 Simpsons’ Hidden Talents
不可不戒
博客等级 码龄16年 90粉丝 508原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值