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

官网下载STM32系列芯片的产品选型手册 官方提供了产品选型手册,便于工程师们进行产品选型。 那么,在哪下载"产品选型手册"呢?请看下文。 阅读详情
   

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


危废焚烧优化控制系统设计与实现:基于数据驱动的控制参数预测 本文提出了一种基于数据驱动的危险废物焚烧过程优化控制方法。系统利用历史运行数据和实时监测数据,通过深度学习模型预测关键控制参数,实现焚烧过程的智能化控制。系统采用Python开发,结合TensorFlow/PyTorch框架,构建了完整的数据采集、预处理、特征工程、模型训练和实时预测闭环系统。该系统能够处理多变量非线性关系,适应工况变化,从历史数据中学习最优控制策略,相比传统PID控制方法具有显著优势。论文详细介绍了系统架构、算法设计和实现细节,为危废焚烧过程的优化控制提供了有效解决方案。 阅读详情

相关推荐

JSON(详解)

JSON(JavaScript Object Notation)是一种轻量级的数据交换格式。它以易于阅读和编写的文本格式来存储和表示数据,通常用于在不同的系统之间进行数据交换。JSON数据以键-值对的形式组织,可以包含对象、数组、字符串、数字等基本数据类型。它经常在Web开发、API通信等领域被广泛使用。

7722

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

Mplus—验证性因素分析(Confirmatory Factor Analysis, CFA)

介绍一阶和二阶验证性因素分析概况及在Mplus中的操作方法。

m0_54401011的博客 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的成长之路 1238

STM32F103C8T6+I2C+DMA读取陀螺仪模块JY901S(硬件I2C

说明:1.本实验代码适用移植一切stm32f1系列;2.本实验使用的是外设资源硬件I2C2;3.本实验运用的是DMA单次模式,如果需要DMA的循环模式,请移步我的另一篇文章;4.本文章不提供陀螺仪校准教学,并是在没有校准陀螺仪情况下读取数据;5.本文章是作者的学习记录及心得,如有不足,欢迎指正。 总结:亲测stm32f103c8t6最小系统板通过片上外设资源I2C配合DMA读去陀螺仪模块jy901s偏航角有效。

anquanyuanqqadsy的博客 6184

不用Root!这些隐藏代码能一键开启安卓诊断端口(小米/OPPO/魅族机型实测)

本文提供了一份无需Root权限即可开启安卓手机诊断端口的实用指南。通过拨号盘输入特定隐藏代码,小米、OPPO、魅族等机型的用户可以一键激活此工程模式,从而连接电脑进行基带数据备份(如QCN文件)或故障排查。文章详细列出了各品牌指令、操作验证步骤,并强调了备份IMEI等关键数据的重要性与操作风险,旨在帮助用户在紧急情况下修复网络问题。

weixin_29260291的博客 282

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

CANOE DIVA 工程怎样在具体服务前增加前置条件

然后会在CANoe的Test Module视窗中发现一个跟系统条件相关的Test Module模块,在该模块中有生成跟系统条件相关的CAPL 脚本。这里需要根据你的实际项目进行更改,diva工程加载到canoe的工程的时候,会同步加入你创建的cdd文件,这里示例的ABS_ESP 就是你的cdd的ECU命名,后面就是具体的前置条件服务。4、配置完成后,测试用例就会如下图Trace窗口所示,在每一次10 02请求之前都会调用CAPL Function的PreconditionCheck函数中定义的脚本。

weixin_45940007的博客 1993

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

解决com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60027, active 20, maxActive 20错误

全网详细解决com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60027, active 20, maxActive 20, creating 0, createErrorCount 24的错误

念兮为美 417

点云去噪:基于点云拟合的方法

点云处理是计算机视觉中的重要任务之一,而点云去噪是点云处理的关键步骤之一。在实际应用中,由于采集设备的噪声、运动估计误差或者环境干扰等因素,点云数据中常常包含有噪声点,这些噪声点会对后续的点云分析和处理造成不良影响。一种简单的方法是计算点到拟合曲面的距离,并将距离超过某个阈值的点定义为噪声点,进行过滤。一种简单的方法是计算点到拟合曲面的距离,并将距离超过某个阈值的点定义为噪声点,进行过滤。该方法通过拟合点云数据的曲面模型,对噪声点进行识别和过滤,从而得到更加干净的点云数据。

AuSwift的博客 644

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

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

Tc的专栏 999

OceanBase备租户创建(二):通过BACKUP DATABASE PLUS ARCHIVELOG

OceanBase数据库备租户创建方法二:通过BACKUP DATABASE PLUS ARCHIVELOG功能实现,特别适用于社区版和单机版部署模式。

Sebastien23的博客 560

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

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

NTscan扫描工具

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

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

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

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

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 735

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

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的技术栈 2670

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 1160

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

HDU 1867 A + B for you again kmp算法

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

弱智就要多努力 675

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

HDU 1867 A + B for you again (KMP)

KMP

NeWnIx 693

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、付费专栏及课程。

余额充值