kmp&&hdu 1711 next数组

Android Camera性能优化概述 做camera性能优化方面的工作有几年了,想写一篇文章简单介绍一下其中涉及到的具体技术,这篇文章会大概介绍一下涉及到的技术。 阅读详情

kmp这几天一直都在搞这个,今天A了hdu的1711这题,就是简单的kmp模板题;

kmp的核心就是next数组;这几天一直在看严蔚敏的数据结构课本,上面介绍的是

next[j]={

                 0,j==1,

max{k| 1<k<j,且P1P2'……Pk-1==Pj-k+1........Pj-1},

1,

}

next[j]表示1到k-1中最长首尾重复子串的长度+1,也就是当模式串的第[j]个和文本串中的第[i]个不匹配时,主串指针i不用回溯,而只需模式串的j=next[j],假设文本串是S,模式串是P则下次S[i]和P[next[j]]比较,j应该回溯到next[j];

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
using namespace std;
const int N=1000003;
int next[N];
int a[N],b[N];
void getNext( int str[], int pos ,int len) {

    if(next == NULL || str == NULL )
        return ;

        next[0] = -1;

        int i=pos,j=-1;

        while( i < len) {

            if(j == -1 || str[i] == str[j]) {
                i++;
                j++;
                next[i] = j;//
            }
            else {
                j=next[j];
            }
        }
}
int main()
{
//freopen("1.txt","r",stdin);
//freopen("2.txt","w",stdout);
     int T;
    scanf("%d",&T);
    while(T--){
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);

        }
        for(int i=0;i<m;i++) {
            scanf("%d",&b[i]);
        }
        getNext(b,0,m);
        int i=0,j=0;
        while(i<n && j<m ){
            if(j == -1 || a[i] == b[j]){
                i++;
                j++;
            }
            else{
                j=next[j];
            }
        }
        if(j==m){
            printf("%d\n",i-m+1);
        }else{
            printf("-1\n");
        }
    }
    return 0;

}


立创电赛C题:基于STM32的三端口DC-DC变换器设计与MPPT算法实现 本文详细解析了2021年立创电赛C题——基于STM32的三端口DC-DC变换器设计。文章从题目要求出发,系统阐述了采用双DC-DC电路(分别负责MPPT追踪与稳压)的硬件架构,并重点讲解了以STM32为核心、结合PID控制与扰动观察法(MPPT算法)的软件实现方案,为备赛者提供了完整的软硬件设计思路与调试经验。 阅读详情

相关推荐

瑞萨CS+仿真器高级配置指南:从原理到实战优化RX系列MCU调试

在嵌入式系统开发中,仿真器是进行早期验证和深度调试的核心工具。它通过精确模拟目标微控制器的指令集、内存和外设行为,构建了一个虚拟的硬件沙盒环境。其工作原理在于对CPU核心、时钟系统和外设接口的软件模拟,使开发者能在无物理硬件时进行代码逻辑验证、内存布局规划和时序分析。这项技术的核心价值在于大幅降低开发成本、加速问题定位,并支持复杂场景的复现与测试。在瑞萨RX系列MCU开发中,CS+集成开发环境内置的仿真器功能尤为强大。本文聚焦于**指令解码缓存**和**外设时钟比率**等关键配置的深度解析,阐述如何通过优化

cmff98425的博客 1125

(HDU - 1711)Number Sequence

(HDU - 1711)Number Sequence Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b[1]

The wind of freedom blows 575

ROS激光雷达动态避障算法优化(C++实战)

本文深入探讨了ROS激光雷达动态避障算法的C++实战优化。针对动态环境的核心挑战,文章系统性地介绍了从激光数据预处理(降噪、瘦身)、动态障碍物检测与跟踪,到基于动态窗口法(DWA)的智能决策与调优的全流程。重点分享了如何将障碍物速度预测融入DWA打分函数,以实现更安全、流畅的避障,并提供了工程架构、性能优化及真机调试的实用建议。

weixin_29192141的博客 947

HDU1711 Number Sequence(KMP)

Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 40595    Accepted Submission(s): 16759Problem Description Given two sequence...

Low Coder的博客 234

【OpenClaw 实战】Ubuntu 双机 Gateway + Node 部署全流程 + 所有常见坑(2026版)

如果你只是需要浏览器自动化、截屏、简单系统查询 →Node 模式够用,别折腾 exec。如果你需要 GOLD 运行任意 shell 命令、git、npm、自定义脚本 →必须升级成 Gateway。bind lan + pairing approve + token 统一。后续想玩多 Agent 团队,优先考虑双/多 Gateway + 聊天通道互发(社区已有不少成功案例)。欢迎评论区留言你的环境和报错,一起交流!

hampeter的博客 1547

【49】Camunda8-Self-Managed部署之Docker方式

围绕camunda8 self-managed,介绍了基于Docker部署相关服务的过程。

AlieNeny的博客 1682

hdu 1715 (java版)

import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int z = 0; z

garbagebin的博客 201

VisionPro实战:5个工业视觉检测案例详解(附代码片段)

本文详细解析了VisionPro在工业视觉检测中的5个实战案例,包括PCB焊点质量检测、汽车齿轮尺寸测量、药品包装缺陷检测等。通过硬件配置方案和软件算法流程的详细介绍,帮助工程师快速掌握VisionPro的应用技巧,提升工业自动化检测效率。

weixin_29284657的博客 520

HDU 1711 Number Sequence(KMP算法)

Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 21891    Accepted Submission(s): 9350 Problem Description Given tw

超越自我就是成功 417

2026华为OD机考新系统真题 + 双机位C卷 + 往年真题 - 题库目录分值说明 + 考点说明+在线OJ

2026年4月1日起,华为OD机试正式切换至新系统模式!采用力扣模式,无需自己写输入! 难度大幅度降低。正在备考华为OD机试的同学,优先刷新系统机试真题,可大幅提升通过率。 新系统考题考点与旧版一致,无需重新适应。本专栏所有算法题均配有详细思路解析,并提供C语言、JS、C++、Python、Go、Java多语言源码实现。订阅后私信即可开通专属OJ刷题权限,高效备考一次上岸!

算法大师! 45万+

MATLAB与图像处理(一):图像中结构张量的求法(Structure Tensor)

1.结构张量的作用:       能够区分图像中的平坦区域,边缘,角点; 2.图像中的结构张量的定义    1)是一个矩阵;    2)与图像的水平,垂直梯度有关,定义如下: 在MATLAB中,可以用如下语句求解:[Ix,Iy]=gradient(Image); 3)求出结构张量矩阵的行列式,和迹(矩阵对角线之和)   行列式:K=det(E);   迹:  

wenyusuran的专栏 5242

hdu-1711-Number Sequence-kmp-java

Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b

lijinyuliangyan的博客 566

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

HDU-1711-Number Sequence

HDU-1711-Number Sequence http://acm.hdu.edu.cn/showproblem.php?pid=1711 KMP模版 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; using namespace std; #define N 1000005 #defin...

java开发指南博客 【转载】 209

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

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

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

HDU1711 KMP

Number Sequence Time Limit: 10000/5000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14563Accepted Submission(s): 6392 Problem Description Given two sequen...

weixin_30721077的博客 116

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

HDU 1711 Number Sequence kmp算法

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1711 题意:给定两个数组,问能不能再第一个数组中匹配得到第二个数组,如果可以,那么输出最早匹配的起始位置,否则输出-1 思路:kmp直接匹配即可,中间写搓了一个地方,晕-_-|| #include #include #include #include using namespace std;

弱智就要多努力 2009

hdu1711

Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8078 Accepted Submission(s): 3670 Problem Description Given...

weixin_33762130的博客 128

KMP - HDU 1711 Number Sequence

Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11606    Accepted Submission(s): 5294 Problem Description Given two sequence

北岛知寒 297

hdu1711 KMP应用之详细讲解

Kmp算法详细看严蔚敏的视频教程很详细很好 NumberSequence TimeLimit:10000/5000MS(Java/Others)MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):5047AcceptedSubmission(s):2275 ProblemDescription Giventwosequenceso...

java开发指南博客 【转载】 221

HDU1711(KMP算法)

Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 44477 Accepted Submission(s): 18293 Problem Description Given two sequences...

八百标兵奔北坡的博客 456

HDU 1711 Number Sequence(KMP)

/* 最基础的KMP算法题,只是把字符改为了数字 */ #include &lt;cstdio&gt; const int mMax = 10007; const int nMax = 1000007; int N, M; int a[nMax],b[mMax]; int next[mMax]; void init() { scanf("%d %d", &amp;N, &amp;M); int...

java开发指南博客 【转载】 159

HDU-1711 Number Sequence kmp算法

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1711 题目 Number Sequence  Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)  Total Submission(s): 32182 Accepted Submis...

立志变成java巨头 296

HDU1711 (匹配第一个子串的位置)

Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 40539 Accepted Submission(s): 16730 Problem Description Given two seque...

越看越喜欢啊 420

http://acm.hdu.edu.cn/showproblem.php?pid=2795区间最大值

刚开始时感觉本题是二维线段树,然后分析一下貌似不是,就是求取区间最大值的位置,感觉和之前的那道求逆序数的有一部分很像,查询更新;这题是把查询和更新合在了一起;但是我这个弱菜不会写代码,之后果断参考了HH神牛的模板;ORZ。。。各种若,弱不经风,刚学线段树,以后要努力,第一次这么晚了还在写代码了,ORZ。。只有我这种若才才会熬夜。。。 好了今天到这里一会碎觉喽,不然会挂的。这几天看到网上很多新闻因

2826

http://poj.org/problem?id=3468线段树简单 成段更新 区间求和

这题是昨天的比赛题,昨天比赛完美被大一的虐了,感觉自己真是白活了,一头撞死算了,人家大一的做了5题,而我这个水货这做了两道签到题;明显昨天知道这个题目是线段树,刚开始还想用树状数组试试,后来写完了发现不是插线问点,结果可想而知,代码重写,再看时线段树,然后不会了,自己只会单点更新,以后努力了,没有时间给自己犹豫了;抓紧时间学习数据结构,还有贪心,图论,搜索,还有C++;任重道远; 其中本题的延迟

1853

给出一个n个元素的链表输出倒数第k个节点

用两个指针;初始化为头指针;用其中一个指针遍历链表,当该指针遍历到第k个节点时,另外一个指针开始从头节点开始遍历链表;两个指针之间的距离为k;遍历完链表时第二个指针所指向的节点就是倒数第K个: #include #include #include using namespace std; struct node{ int val; node *next; node(){

1563

http://acm.nbut.cn/Problem/view.xhtml?id=1186二叉树的宽度

昨天比赛时我代码没有写出来还好思想有了,跟魁永说了,他也是这个想法;然后就做了,代码写了好久啊(感觉真是弱死了,而且wa了一次),今天自己写了1Y;感觉真是弱爆了;以后搜索要抓紧练习了; #include #include #include #include using namespace std; struct node { node() {lc=rc=-1;} int lc,rc; }

1400
上一篇: unix 网路编程(卷一)第一个程序编译过程
下一篇: C++虚函数
Java_beginer1
博客等级 码龄16年 22粉丝 84原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值