hdu 2594 Simpsons’ Hidden Talents ( kmp )

本文介绍了一个有趣的字符串匹配问题:寻找两个字符串S1和S2之间最长的相同前缀和后缀。通过将两个字符串连接并使用特殊字符分隔,利用KMP算法求解next数组来高效找到匹配长度。

Simpsons’ Hidden Talents

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3508    Accepted Submission(s): 1307


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
 

题目大意: 给出两个字符串S1和S2,求取S1的前缀与S2的后缀中相同的且长度最大的串及其长度
将两个字符串连接,中间用不出现的字符间隔,直接kmp求取next数组,next[len]即为所求
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define MAX 50007

using namespace std;

char s1[MAX<<1],s2[MAX];

void get_next ( char p[] , int next[] )
{
    int i = 0 , k = -1 , len = strlen (p);
    next[0] = -1;
    while ( i < len )
        if ( k == -1 || p[i] == p[k] ) 
            i++,k++,next[i] = k;
        else k = next[k];
}

void solve ( char s[] )
{
    int len = strlen ( s );
    int next[MAX<<1];
    get_next ( s , next );
    if ( next[len] )
    {
        for ( int i = 0 ; i < next[len] ; i++ )
            printf ( "%c" , s[i] );
        printf ( " " );
    }
    printf ( "%d\n" , next[len] );
}

int main ( )
{
    while ( ~scanf ( "%s" , s1 ) )
    {
        scanf ( "%s" , s2 );
        int len1 = strlen(s1);
        int len2 = strlen(s2);
        for ( int i = 0 ; i < len2 ; i++ )
            s1[i+len1+1] = s2[i];
        s1[len1] = '#';
        s1[len1+len2+1] = 0;
        solve ( s1 );
    }
}



当前,全球经济格局深刻调整,数字化浪潮席卷各行各业,智能物流作为现代物流发展的必然趋势和关键支撑,正迎来前所未有的发展机遇。以人工智能、物联网、大数据、云计算、区块链等前沿信息技术的快速迭代与深度融合为驱动,智能物流不再是传统物流的简单技术叠加,而是正在经历一场从自动化向智能化、从被动响应向主动预测、从信息孤岛向全面互联的深刻变革。展望2025年,智能物流系统将不再局限于提升效率、降低成本的基本目标,而是要构建一个感知更全面、决策更精准、执行更高效、协同更顺畅的智慧运行体系。这要求我们必须超越传统思维定式,以系统化、前瞻性的视角,全面规划和实施智能物流系统的建设。本实施方案正是基于对行业发展趋势的深刻洞察和对未来需求的精准把握而制定。我们的核心目标在于:通过构建一个集成了先进感知技术、大数据分析引擎、智能决策算法和高效协同平台的综合智能物流系统,实现物流全链路的可视化、透明化和智能化管理。这不仅是技术层面的革新,更是管理模式和服务能力的全面提升。本方案旨在明确系统建设的战略方向、关键任务、技术路径和实施步骤,确保通过系统化部署,有效应对日益复杂的供应链环境,提升整体物流韧性,优化资源配置效率,降低运营成本,并最终为客户创造更卓越的价值体验。我们致力于通过本方案的实施,引领智能物流迈向更高水平,为构建现代化经济体系、推动高质量发展提供强有力的物流保障。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值