A + B for you again hdu1867(KMP的应用)

48、住宅抵押贷款支持证券的定价、风险评估与结构化设计 本文深入探讨了住宅抵押贷款支持证券(RMBS)的定价、风险评估与结构化设计。内容涵盖提高定价准确性的方差缩减方法,如准蒙特卡罗序列的应用;分析RMBS面临的利率风险、信用风险和模型风险,并提出相应的度量与应对策略;介绍利用动态规划优化CMO分层结构以最大化发行利润的方法。同时总结了RMBS的基本类型、定价流程及市场发展趋势,为投资者和发行人提供全面的决策支持。 阅读详情
   

A + B for you again


Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between them is “asdfg”, for “sdf” is the tail substring of “asdf” and the head substring of the “sdfg” . However, the result comes as “asdfghjk”, when you have to add “asdf” and “ghjk” and guarantee the shortest string first, then the minimum lexicographic second, the same rules for other additions.

Input
For each case, there are two strings (the chars selected just form ‘a’ to ‘z’) for you, and each length of theirs won’t exceed 10^5 and won’t be empty.
Output
Print the ultimate string by the book.
Sample Input
asdf sdfg
asdf ghjk
Sample Output
asdfg
asdfghjk
题意:连个字符串相加,要求如果a的后缀和b的前缀匹配,就只输出一个,即重合,要求第一输出的字符串最短,其次按照字典序输出思路:其实这是一道很好的KMP的应用及其变形,kmp算法是查找一个目标字符串中的模板串,而这道题并没有让我们去查找是否含有模板串,而是去找后缀的匹配长度,实际上仍然是使用kmp算法,让kmp算法整个循环结束最后返回最后的下一次要查找的坐标就可以,实际就是Next[i]的值,就是末尾已经匹配好的长度,比较两次选出最短的就可以了code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int Next[100100];
char s1[100100],s2[100100];
void getNext(char s[]){
    int i,j;
    i = -1;
    j = 0;
    memset(Next,0,sizeof(Next));//先初始化一下Next数组
    Next[0] = -1;
    int lens = strlen(s);
    while(j < lens){
        if(i==-1||s[i]==s[j]){
            i++,j++;
            if(s[i]==s[j]) Next[j] = Next[i];
            else Next[j] = i;
        }
        else i = Next[i];
    }

}
int Kmp(char s[],char m[]){//s是目标字符串,m是模板字符串
    int i = 0,j = 0;
    int lens = strlen(s);
    getNext(m);
    while(j < lens){
        if(i==-1||m[i]==s[j]){
            i++,j++;
        }
        else i = Next[i];
    }
    return i;//实际上这道题并不是让我们找目标字符串中是否含有模板串,而是在后缀中找到相匹配的,所以一路循环到最后得到的i就是相应的目标串中后缀和模板相匹配的长度
}
int main(){
    while(~scanf("%s%s",s1,s2)){
        //分别求两边,看谁当目标串的时候后缀能匹配的最长
        int str1 = Kmp(s1,s2);//s1当目标,s2当模板
        int str2 = Kmp(s2,s1);//s2当目标,s1当模板
        if(str1==str2){//如果相同,那么按字典序顺序
            if(strcmp(s1,s2)<0)printf("%s%s\n",s1,str1+s2);//s2字符串字典序大,先输出s1,然后从str1位置开始输出字符串s2,因为前面的是匹配的
            else printf("%s%s\n",s2,str1+s1);//同理
        }
        else if(str1>str2){
            printf("%s%s\n",s1,str1+s2);//s1后缀匹配的长,先输出s1,然后从s2的str1位置开始输出s2
        }
        else printf("%s%s\n",s2,str2+s1);//s2后缀匹配长,先输出s2,然后从s1的str2位置开始输出s1
    }
    return 0;
}


YOLOv8性能突破:DySample超轻量动态上采样算子的创新应用与实现【附保姆级代码】 YOLOv8(You Only Look Once Version 8)作为YOLO系列模型的最新版本,延续了高效、准确的目标检测优势。其基础结构包含了骨干网络(Backbone)、检测头(Head)、以及特征融合层(Neck)。在特征融合阶段,YOLOv8需要对不同尺度的特征图进行上采样,以便将低分辨率的特征与高分辨率的特征进行融合。传统的上采样操作多使用插值(如双线性插值)或固定卷积,而这些方法可能无法很好地适应复杂的上下文信息。 阅读详情

相关推荐

Win11如何更改用户文件夹名(完整流程- 已验证可行)

把C盘所有文件备份,如果不想备份,则选择创建一个C盘的系统还原点(能在后续把C盘玩崩之后恢复原状)

Y_Aryan的博客 5万+

HDU1867:A + B for you again

Problem Description Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of

ACM!荣耀之路! 2382

Win 11 Fastboot驱动的详细安装教程

Fastboot驱动的详细安装教程

水w的博客 1万+

HDU1867 A + B for you again KMP应用

Problem DescriptionGenerally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the

Bill_Utada的成长之路 1236

XPe开发初体验(一)XPe概述

XP Embedded是微软Windows Embedded产品线中非常重要的一环,不过比起大名鼎鼎的Windows Embedded CE,XPe显得过于低调了。在接下来的一段时间里,我希望能够用六篇的篇幅来描述一下XPe的整个开发过程。这个系列文章主要是针对有Windows编程经验,但是没有嵌入式开发经验的开发者,提供一些概念和开发过程的初步介绍。XP Embedded是一个基于Windo

aawolf = new Mobile.MVP 1万+

WPF数据可视化:LiveCharts自定义X轴与Y轴的5个实战技巧(附完整代码)

本文详细介绍了在WPF应用中使用LiveCharts进行数据可视化时,自定义X轴与Y轴的5个核心实战技巧。内容涵盖精确控制刻度步距、深度定制视觉样式、实现多轴布局对比、优化显示空间以及构建响应式动态轴,并提供了完整的C#和XAML代码示例,帮助开发者创建专业且用户体验出色的图表。

moss5的博客 690

hdu 1867 A + B for you again(KMP灵活应用)

Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between ...

vocaloid01的博客 293

二、频率调制光谱(FMS)技术——error信号的数学模型及其他推论

一些推论。

qq_41111336的博客 1604

hdu 1867(A + B for you again) KMP的应用 /hdu 2594(Simpsons’ Hidden Talents) KMP

今天对KMP的认识又加深一点了,可是又不是很能用语言来表达! 题目大意:给定两个字符串,比如abcd,dcab,需要把它连接起来,但是需要遵循两个条件,1 最短原则 2 长度相同的前提下字典序的优先 连接原则:如果第一个字符串的后缀(长度为n)和第二个字符串的前缀(长度为n)相同,那么连接的时候可以省去相同的n个字符,本来有2n个字符; 仍然以上面的两个字符串为例,有两种连法,abcd...

weixin_30629977的博客 150

Docker部署OnlyOffice踩坑实录:解决editor.bin下载失败的3种姿势

本文详细解析了Docker部署OnlyOffice时editor.bin下载失败的常见原因,并提供了三种核心解决方案。重点剖析了容器网络配置、Nginx反向代理(特别是proxy_pass设置)以及安全策略调整,帮助开发者彻底解决静态资源加载问题,确保文档协作平台稳定运行。

weixin_29281941的博客 870

各大厂薪资对比爬虫:Python采集OfferShow爆料数据

print(f"⚠️ API返回错误码: {data.get('code')}, msg: {data.get('msg')}")ax.set_title('各大厂薪资对比 (基于OfferShow爆料数据)', fontsize=16, fontweight='bold')stats.columns = ['人数', '平均年薪', '年薪中位数', '年薪标准差', '平均月薪', '平均月数']print(analyzer.get_position_stats('字节跳动').head(10))

2201_76125261的博客 602

HDU 1867 A + B for you again (KMP应用)

HDU 1867 A + B for you again (KMP应用)

Tc的专栏 999

【深度学习新浪潮】李飞飞团队VAGEN框架深度解析:让VLM智能体学会“三思而后行“

VAGEN框架的真正价值,不仅在于性能指标的突破,更在于重新定义了VLM智能体的发展方向——人工智能的进步不应只追求"做得对",更要实现"想得清"。李飞飞团队通过强制显式思考、动态表示适配和精细化奖励三大创新,让智能体第一次具备了可解释的世界建模能力。正如人类通过"观察-预测-行动"认识世界,VAGEN为AI注入的这种思考范式,或许正是通往通用人工智能的关键一步。对于开发者而言,开源的VAGEN框架不仅提供了强大的工具,更揭示了一个重要理念:让AI学会思考,比让它学会执行更重要。

专注:太空算力、AI infra、异构调度、大模型成本工程 280

HDU 1867 A + B for you again 数据结构+KMP简单应用

A + B for you again 数据结构+KMP简单应用 Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u SubmitStatus Description Generally speaking, there are a lot of problems about s

fans_ac的博客 343

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

【HDU - 1867 】A + B for you again(KMP,next数组应用)

题干: Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition bet...

xuanweiace的博客 236

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

HDU 1867 A + B for you again(KMP算法的应用)

A + B for you again Time Limit: 5000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4496Accepted Submission(s): 1157 Problem Description Generally spea...

weixin_33734785的博客 135

HDU1867 A + B for you again【KMP】

A + B for you again Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9765 Accepted Submission(s): 2410 Problem Description Generally speaking...

海岛Blog 732

【KMP】 hdu1867 A + B for you again

A + B for you again http://acm.hdu.edu.cn/showproblem.php?pid=1867 Problem Description Generally speaking, there are a lot of problems about strings processing. Now you encounter another su

Ted's 游乐园 1953

HDU - A + B for you again(KMP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1867Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Generally speaking, there are a lot of problem...

ityanger的技术栈 2668

hdu1867---A + B for you again

A + B for you again Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4633    Accepted Submission(s): 1192 Problem Description Generally

Alex 1159

【hdu1867】A + B for you again——KMP

题目: A + B for you again Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5914    Accepted Submission(s): 1463 Problem Description

CFhM_R's Blog 489

HDU 1867 A + B for you again kmp算法

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1867 题意:给定两个字符串,把一个字符串接在另一个字符串的后面,相接部位若有相同,则可以略去其中一个字符串的相同部分,输出拼接后最小长度的字符串,若有两种最小长度的字符串,输出字典序较小的那个 思路:可以用kmp匹配一个字符串的尾部和另一个字符串的首部相同的最大长度,然后交换两个字符串的次序,再来一次

弱智就要多努力 673

hdu 1867:A + B for you again(kmp)

http://acm.hdu.edu.cn/showproblem.php?pid=1867 Problem Description Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two st...

300

杭电 hdu 1867 A + B for you again

杭电 hdu 1867 A + B for you again kmp算法 简单题

panyanyany(飞雨幻沙) 1316

hdu1867 A + B for you again(kmp)

题目链接:点这里!!!! 题意:(简单易懂自己看) 题解:直接kmp,但是要注意在+号前面的字符串指针一定要指到最后!!! 代码: #include #include #include #include #include #include #include #include #include #include #include #include #inclu

Zsss的博客 390

HDU 1867 A + B for you again (KMP)

KMP

NeWnIx 692

hdu 1867 kmp A + B for you again

hud-1867- A + B for you again   Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and

---小菜鸟--- 395
上一篇: Xiao Ming's Hope HDU - 4349(Lucas定理)
下一篇: Cyclic Nacklace (kmp next数组的应用)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值