#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#include <ctype.h>
#include <bitset>
#include <iostream>
#define maxn 100009
#define inf 0x3f3f3f3f
#define mod 1000000007
#define Mat_size 11
using namespace std;
char s[maxn];
int _next[maxn],f[maxn],len;
void getnext()
{
int j=0,i=_next[0]=-1;
while(j<len)
{
if(i==-1||(s[i]==s[j]))
{
i++;
j++;
_next[j]=i;
}
else
i=_next[i];
}
}
int kmp(int l,int r,int t)
{
int i=0,j=l;
while(j<=r)
{
if(i==-1||s[j]==s[i])
{
j++;
i++;
if(i==t)
return 1;
}
else
i=_next[i];
}
return 0;
}
int main()
{
// freopen("d:\\in.txt","r",stdin);
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%s",s);
len=strlen(s);
getnext();
int k=_next[len];
while(k)
{
if(k<=len/3&&kmp(k,len-k-1,k))
break;
k=_next[k];
}
printf("%d\n",k);
}
return 0;
}
相关推荐
CMOS sensor 基础
NA
KMP模板
//KMP模板 #include<bits/stdc++.h> using namespace std; void get_next(string t, int* next){ int i=0; int j=-1; next[0]=-1; while(i<t.length()){ if(j==-1||t[i]==t[j]){ i++,j++; next[i]=j; } else{ j=next[j]; } } } int kmp(string
推荐算法之Thompson(汤普森)采样
如果想理解汤普森采样算法,就必须先熟悉了解贝塔分布。 一、Beta(贝塔)分布 Beta分布是一个定义在[0,1]区间上的连续概率分布族,它有两个正值参数,称为形状参数,一般用α和β表示,Beta分布的概率密度函数形式如下: 这里的Γ表示gamma函数。 Beta分布的均值是: 方差: ...
KMP模板代码
终于自己根据理解,手搓了一个自己的AC代码模板了,,,真不容易,,小细节还是有的,而且跟网上的模板普遍存的不是很一样,next[i]表示第i个位置匹配完了,第i+1个位置要匹配的位置 例:ababa 第二个a的next值是2,表示第二个a与第一个a可以匹配上,下一个要看的位置就是第一个b,是否匹配 不过只判是否存在字串,有函数可以用,也是很爽的。 模板代码: void getne...
省一蓝桥杯嵌入式-09RTC实时时钟
RTC(Real-Time Clock)实时时钟,是一个独立的定时器RTC模块拥有一组连续的计数的计数器,在响应软件配置下,可提供时钟、日历、闹钟功能RTC能提供年月日时分秒等信息(可设置)在系统复位或从待机模式唤醒后,RTC的设置时间维持不变(这个我没实现,复位后时间也重置了,有能力的可以自己研究一下)持续时间跟踪:在主系统断电后或处于低功耗模式时,RTC仍继续工作,原理是有额外的电池为其供电(蓝桥杯板子没有这个备用电源,该功能无效。
Ships Dataset:解锁海洋探索的数字宝库
在海上交通管理中,通过对船舶的持续跟踪,可以及时发现船舶的异常行为,如偏离航线、超速等,保障海上航行的安全。例如,通过分析船舶的航行数据和位置信息,合理安排船舶的停靠时间和装卸货物顺序,避免港口拥堵,提高船舶的周转率。同时,还精确标注了船舶在图像中的位置坐标,通过这些坐标,我们可以准确地定位船舶在图像中的具体位置,为后续的分析和处理提供了精确的依据。从繁忙运输货物的货船,到承载着能源使命的油轮,再到穿梭于海洋寻找鱼群的渔船 ,每一种船舶都有着独特的外形和功能,在数据集中留下了它们的身影。
KMP模板(C++)
这是一个KMPC++的模板。相信很对同学看了大佬超详细的讲解(本文有链接),但还是不太清楚next数组的意义,或者为什么next[0]=-1,而不是1。Kmp的时间复杂度为什么是线性的
nnDetection实战:手把手教你用Python在自家电脑上跑通第一个肺结节检测模型
本文详细介绍了如何使用nnDetection框架在普通电脑上实现肺结节检测模型的搭建与运行。从环境配置、数据预处理到模型训练与推理,手把手教你完成医学图像检测的全流程,特别适合初学者入门医学AI领域。
几道KMP模板题
几道KMP的模板题 记录下KMP学习过程 注意:这里的模板s1是文本串s2是匹配串(模式串) HDU1711 Number Sequence链接 最小匹配位置 #include<iostream> #include<bits/stdc++.h> #include<queue> #include<vector> using namespace std; typedef long long ll; const ll maxn=1e6+5; const ll MOD
C# 固高板卡(总线型) 操作类
主要功能有:初始化,轴使能,正负方向手动移动,回0,点到点移动,等待移动完成,输入IO数据读取,输出IO控制,清除报警等功能。
微信小程序:errno: 600001, errMsg: “uploadFile:fail errcode:-101 cronet_error_code:-10001 error_msg:net::E
微信小程序报错uploadFile:fail errcode:-101 cronet_error_code:-10001 error_msg:net::ERR_CONNECTION_RESET, custum ip is invalid, didn't find user's ip,wx.uploadFile errno: 600001 errcode:-101 ?微信小程序wx.uploadFile错误,wx.uploadFile 在真机上报下面的错误,调试工具里没有问题,其它接口在真机/调试工具都正常,
[kmp+模板] kmp模板
文章目录0. 前言1. kmp 0. 前言 kmp 模式匹配算法很牛,一般结合 kmp 的题目都不怎么简单,或是困难题目可以采用 kmp 的思想很快搞定,之前博文有写过 kmp· 算法原理,和简单实现了下,但是由于当时认识浅薄,大家看看就好。在此总结一个简单的 kmp 算法模板。 当时的博文:[杂谈] 12. BF、KMP、RK Algorithm 字符串匹配算法 1. kmp 这里是拿数组模拟栈。 模板代码: #include <iostream> using namespace std;
【AI应用实战-Codex】Mac intel芯片下安装Codex(二)
摘要:本文介绍了在Intel芯片Mac上安装OpenAI Codex桌面应用时遇到的问题及解决方法。由于官方仅提供ARM64版本,导致Intel Mac无法直接运行。解决方案包括:1)使用社区脚本将ARM版DMG与x64 Electron重新打包成兼容版本;2)使用VSCode插件配合CLI作为替代方案。文章详细记录了重新打包过程中遇到的"electron_common_owl_features"绑定缺失错误,通过注入stub代码、重算ASAR完整性哈希等步骤成功解决问题。最终生成的Co
KMP模板和模板题目
package 算法模板; import java.util.*; public class KMP { public static void prefix_table(char pattern[],int prefix[],int n) {//找到表 prefix[0] = 0; int len = 0; int i = 1; while(i<n) { if(pattern[i] == pattern[len]) { len++; prefix[i]=len;
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
精雕软件(JDpaint) 5.5 绿色版
精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版
字符串处理、KMP模板:【模板】
KMP算法模板(next函数和kmp) 首先主要感谢一下:July算法从头到尾彻底理解KMP,讲得是究极详细,文底还有视频版讲解。还有河海大学ACM字符串专题讲解,两个小姐姐一真一假让我笑哭,文章中我主要用了这个视频里的模板,很好用,自己手模上三五遍也就懂得差不多了。 ...
计算机控制技术及应用
《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。
KMP算法模板
例题 SDUT OJ 数据结构实验之串一:KMP应用 #include <iostream> #include <cstdio> #include <cstdlib> #include <string.h> #include <algorithm> using namespace std; const int N = 11234567; int n,m; int Next[N]; int a[N],b[N]; void get_next(in
jdk-8u144-linux-x64.tar.gz.
该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包
[c++模板] KMP
给定一个模式串S,以及一个模板串P,所有字符串中只包含大小写英文字母以及阿拉伯数字。 模板串P在模式串S中多次作为子串出现。 求出模板串P在模式串S中所有出现的位置的起始下标。 输入格式 第一行输入整数N,表示字符串P的长度。 第二行输入字符串P。 第三行输入整数M,表示字符串S的长度。 第四行输入字符串S。 输出格式 共一行,输出所有出现位置的起始下标(下标从0开始计数),整数之间...
1657



被折叠的 条评论
为什么被折叠?



