hdu3522 ex-kmp或hash(暂时不理解

探讨了给定两个整数A和B的情况下如何通过将B插入到A中获得最小的新整数C的方法。提供了具体的示例并介绍了使用exkmp算法进行解决的过程。

Minimum Integer sequence

问题描述 :

Now we have two integers A and B, after insert B into A, we can get a new integer C, and then the problem comes: how to get a smallest C? For example, let A = 345, B = 478. As there are there digits in A, so there are four places for B to insert into. We can get 478345, 347845, 344785, 345478.After comparing, we could know that the smallest C is 344785.

输入:

There are multiple test cases. Each test case takes one line, Each line contents two integers A and B(there will be less than 100000 digits in A and B and there is no digit values 0 in A and B), the two integers are separated by a space, process to the end of file.

输出:

There are multiple test cases. Each test case takes one line, Each line contents two integers A and B(there will be less than 100000 digits in A and B and there is no digit values 0 in A and B), the two integers are separated by a space, process to the end of file.

样例输入:

345 478
12345 678
123 123

样例输出:

344785
12345678
112323

参考https://vjudge.net/solution/2446097 用的是exkmp
也有用hash 的 https://vjudge.net/solution/2352588

下面代码是错的。

#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<cstdio>
#include<stack>
#include<iostream>
#include<map>
#include<queue>
#include<cmath>
#include<strstream>
using namespace std;
#define sf scanf
#define pf printf
#define mem(a,b) memset(a,b,sizeof(a));
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define MP make_pair
#define N 3030
#define M 200020
#define mod 998244353
#define ULL unsigned long long
#define LL long long
#define inf 0x3f3f3f3f
//freopen("in.txt","r",stdin);

char  num1[N],num2[N];
int ex[N],nxt[N];
int ls1,ls2;
void exkmp(char s1[],char s2[],int nxt[],int ex[]){
    int i,j,p;
    for(i=0,j=0,p=-1;s1[i]!='\0';++i,++j,--p){
        if(p==-1){
            j=0;
            do p++;
            while(s1[i+p]!='\0'&&s1[i+p]==s2[i+p]);
            ex[i]=p;
        }
        else if(nxt[j]<p){
            ex[i]=nxt[j];
        }
        else if(nxt[j]>p){
            ex[i]=p;
        }
        else{
            j=0;
            while(s1[i+p]!='\0'&&s1[i+p]==s2[i+p])p++;
            ex[i]=p;
        }
    }
}
//看不懂。。。
bool smallerthan(int i,int j){
    if(ex[j]<i-j)return num1[ex[j]+j]<num2[ex[j]];
    if(nxt[i-j]<ls2-(i-j)){ return num2[nxt[i-j]]<num2[i-j+nxt[i-j]];}
    if(nxt[ls2-(i-j)]<(i-j))return num2[ls2-(i-j)+nxt[ls2-(i-j)]]<num2[nxt[ls2-(i-j)]];
    return false;
}
int main(){
    while(~sf("%s%s",num1,num2)){
        exkmp(num2+1,num2,nxt,nxt+1);
        exkmp(num1,num2,nxt,ex);
         ls1=strlen(num1);
         ls2=strlen(num2);
        int ans=0;
        for(int i=0;i<ls1;++i){
            if(smallerthan(i+1,ans))ans=i+1;
        }
        for(int i=0;i<ans;++i)pf("%c",num1[i]);
        pf("%s",num2);
        for(int i=ans;i<ls1;++i)pf("%c",num1[i]);
        puts("");
    }
}
标题中提及的“BOE-B2-154-240-JD9851-Gamma2.2_190903.rar”标识了一款由京东方公司生产的液晶显示单元,属于B2产品线,物理规格为154毫米乘以240毫米,适配于JD9851型号设备,并采用Gamma2.2标准进行色彩校正,文档生成日期为2019年9月3日。该压缩文件内包含的代码资源主要涉及液晶模块的底层控制程序,采用C/C++语言编写,用于管理显示屏的基础运行功能。 液晶模块驱动作为嵌入式系统的核心软件组成部分,承担着直接操控显示硬件的任务,其关键作用在于通过寄存器读写机制来调整屏幕的各项视觉参数,包括亮度、对比度及色彩表现,同时负责屏幕的启动与关闭流程。在C/C++环境下开发此类驱动需掌握若干关键技术要素: 首先,硬件寄存器的访问依赖于输入输出操作,常借助内存映射技术实现,例如在Linux平台使用`mmap()`函数将寄存器地址映射至用户内存空间,进而通过指针进行直接操控。 其次,驱动需处理可能产生的中断信号,如帧缓冲区更新完成事件,因此需注册相应的中断服务例程以实时响应硬件事件。 第三,为确保多线程进程环境下共享资源(如寄存器)的安全访问,必须引入互斥锁、信号量等同步机制来避免数据竞争。 第四,在基于设备树的嵌入式Linux系统中,驱动需依据设备树节点中定义的硬件配置信息完成初始化与参数设置。 第五,帧缓冲区的管理至关重要,驱动需维护该内存区域,保证图像数据准确写入并及时刷新至显示面板。 第六,为优化能耗,驱动应集成电源管理功能,通过寄存器控制实现屏幕的休眠与唤醒状态切换。 第七,针对同显示设备支持的色彩格式差异,驱动可能需执行色彩空间转换运算以适配目标设备的色彩输出要求。 第八,驱动开发需熟悉液晶显示控制器与主处理器间的通信接口协议,如SPI、I2CLVDS等串行并行传输标准。 最后,完成代码编写后需进行系统化验证,包括基础显示功能测试、性能评估及异常处理能力检验,确保驱动稳定可靠。 该源代码集合为深入理解液晶显示控制原理及底层驱动开发实践提供了重要参考,通过剖析代码结构可掌握硬件驱动设计的具体方法与技术细节。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值