Jzoj4439 不是回文串

华为机试【没有回文串】 现在已经存在一个不包含回文串的字符串,字符串的字符都是在英语字母的前N个,且字符串不包含任何长度大于等于2的回文串;请找出下一个字典序的不包含回文。第二行输入一个字符串(输入长度... 阅读详情

我倒是觉得上面那一问难一点呢。。。。

下面一个SAM就没掉了,上面还要加上倍增和马拉车

size为right集合大小,mx为最大长度,跑出parent树,OK搞定

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 2000010
using namespace std;
char str[N]; long long A=0;
int s[N][26],sz[N],f[N],mx[N],v[N],r[N],n,cnt=1,lst=1;
inline int extend(char c){
	int p=lst,np=lst=++cnt,q,nq;
	c-='a'; mx[np]=mx[p]+1; sz[np]=1;
	for(;p&&!s[p][c];p=f[p]) s[p][c]=np;
	if(!p) return f[np]=1;
	q=s[p][c];
	if(mx[q]==mx[p]+1) f[np]=q;
	else{
		nq=++cnt; 
		mx[nq]=mx[p]+1;
		f[nq]=f[q]; f[q]=f[np]=nq;
		memcpy(s[nq],s[q],26<<2);
		for(;p&&s[p][c]==q;p=f[p]) s[p][c]=nq;
	}
}
int main(){
	scanf("%s",str); n=strlen(str);
	for(int i=0;i<n;++i) extend(str[i]);
	for(int i=1;i<=cnt;++i) ++v[mx[i]];
	for(int i=1;i<=n;++i) v[i]+=v[i-1];
	for(int i=cnt;i;--i) r[v[mx[i]]--]=i;
	for(int p,i=cnt;i;--i){
		p=r[i]; sz[f[p]]+=sz[p];
		if(sz[p]>1) A=max(A,1ll*sz[p]*mx[p]);
	} printf("%lld\n",A);
}

【华为OD机试真题 Python语言】72、没有回文串 | 机试真题+思路参考+代码解析 回文串的定义:正读和反读都一样的字符串。 >  现在已经存在一个不包含回文串的字符串,字符串的字符都是在英语字母的前N个,字符串不包含任何长度大于等于2的回文串; >  请找出下一个字序的不包含回文串的、字符都是在英语字母的前N个、长度相同的字符串。 如果不存在,请输出NO。 阅读详情

相关推荐

华为OD机考2025C卷 - 没有回文串 (Java & Python& JS & C++ & C )

华为OD机考2025C卷 - 没有回文串(OD上机考试2025年C卷)。提供在线OJ刷题。Java、C++、Python、C语言、JavaScript题解,并提供完整思路讲解。

算法大师! 2990

华为机试:没有回文串

上的一道原题,还是51Nod上说的清楚一些,这题的描述我看了半天都没有看懂。

OceanStar的博客 1159

没有回文串

已支持Java & JS & Python & C,没有回文串,数位搜索,深度优先搜索,回文子串判断

优快云 2612

[JZOJ4439]不是回文串

题目大意一个只包含小写字母的字符串SS,定义一个子串TT出现值为|T||T|乘上TT在SS中的出现次数。 求出现次数不为11的子串中最大的出现值。|S|≤106|S|\le 10^6题目分析SAM\mathrm{SAM}裸题,直接建SAM\mathrm{SAM},计算即可。 时间复杂度O(|S|)\mathrm O(|S|)。代码实现#include <algorithm> #include <

待成熟的葡萄 1454

【华为OD机试真题 C语言】72、没有回文串 | 机试真题+思路参考+代码解析

现在已经存在一个不包含回文串的字符串,字符串的字符都是在英语字母的前N个,字符串不包含任何长度大于等于2的回文串;第二行输入一个字符串(输入长度

KJ.JK 3223

Word多级标题出现黑块的解决思路(word 数字必须介于1-1638之间)

遇到多级目录出现黑块问题,看到一篇博客完美解决,在此记录。

AI_Optimization的博客 3714

[JZOJ5129][SDOI省队集训2017]字符串

题目大意从n个字符串中依次选出一个子串拼接,求本质不同的数量。SAM我们尽量长化前面的。 于是倒着做,对每个串都要建SAM。 只需要处理开头是某个字符的方案数,SAM的一个节点没有该转移边即可。 大概就这样,懒得写清楚了。#include<cstdio> #include<algorithm> #include<cstring> #define fo(i,a,b) for(i=a;i<=b;i

不来也不去的一只失忆蝴蝶 797

单路径微分相除和微分自乘相减算法(PGC-SDD-DSM)

PGC-SDD-DSM算法通过融合单路微分相除和差分自乘,解决了传统PGC解调技术对调制深度和光强干扰敏感的问题,显著提升了解调稳定性和抗失真能力。其高信噪比、低谐波失真以及对参数变化的鲁棒性,使其在光纤传感领域具有重要应用价值。PGC-SDD-DSM算法在计算复杂度方面具有显著的优势,主要体现在其高稳定性和低谐波失真上。这些优势使其在光纤光学干涉传感器中表现出色,尤其是在面对光强干扰和调制深度变化时。

百态·数智思维 | 聚焦大数据、量化与未来AI 839

找回密码 jzoj 4025 后缀自动机

题目 Kevin是一个热爱字符串的小孩。有一天,他把自己的微信登录密码给忘记了,万般无奈之下只好点“找回密码”。 这时候,网页上出现了当初设定的密保问题:在字符串st中,有若干个内容不同的子串,请问其中字典序第k小的子串是什么? 很可惜的是,Kevin现在已经不会写程序了,所以,他找到了睿智的你来帮忙。 分析 对串创建SAM,然后,拓扑一下,算出每个状态,如果继续往后边走,能够生成多少种...

A_loud_name 572

简单概述人形机器人的“大脑、小脑”

原创 仲翔云人形机器人产业通2024年09月13日 19:41上海人形机器人的大脑和小脑是其控制系统的关键组成部分,它们模拟了人类大脑和小脑的功能,以实现复杂的运动控制和决策过程。

AI生成曾小健3 2069

智警杯1.4---excel可视化

知识点

lulu001128的博客 949

华为机试—回文字符串

给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的。 #include #include using namespace std; int huiwen(char *a){ int len = strlen(a); int i,j=len-1; for(i=0;i<len/2;i++,j--){ if(a[i]!=a[j]){ return

小地盘的诺克萨斯 2626

OpenClaw 快速安装与本地应用实战 —— 每一步都有截图加详细说明,本地AI助手,让打工人也有下属

《OpenClaw 2026开源智能体框架10分钟快速部署指南》摘要:本文提供OpenClaw最新版全平台部署方案,重点解决三大核心问题:1)环境配置优化,通过一键脚本实现3-8分钟快速安装(含国内镜像加速方案);2)初始化配置详解,包含大模型绑定(智普AI/本地模型)与5个高频技能安装;3)实战演示文件自动整理任务。同时总结6类常见故障解决方案,涵盖权限、端口占用等典型问题,确保用户从安装到首个自动化任务落地全程无障碍。特别强调Windows需管理员权限、禁用中文路径等关键注意事项,实现"安装即

weixin_43538316的博客 807

codeforces No to Palindromes!(字符串处理,不能有回文)

题意:给你两个整数n,p,n表示字符串的长度,p表示在字母表中只能用前p个字母。然后给你一个符合没有回文字串的字符串s,求是否有下一个这样的字符串且字典序比s大但最小。 分析:握草啊,做完这题不小心超神排第四了,但是是因为看了大神的思路后才敲出来的【罪过罪过】。大神说: 下一个满足的字符串一定是改变尽量靠右的字符才能得到(字典序),  从最右面开始找,假设当前是第i位,如果i位增加之后满足和

onthewaytotop的博客 901

从零开始:用Neo4j构建你的第一个知识图谱(附完整代码示例)

本文提供了一份从零开始的Neo4j知识图谱构建实战指南。通过一个“经典科幻电影宇宙”的具体案例,手把手教你安装环境、设计图谱模式,并使用Cypher查询语言完成节点与关系的创建、数据查询及可视化,帮助你快速掌握自下而上构建知识图谱的核心技能。

weixin_29053073的博客 471

【机器人】机械臂控制入门技术栈分享

机械臂控制入门技术栈分享1.前言2.机器人控制入门技术栈2.1.空间描述和变化2.2.运动学分析2.3.动力学建模2.4.控制入门学习3.进阶部分3.1.机器人参数辨识3.2.非线性控制3.3.现代机器人描述方法:指数坐标4.总结 1.前言 今天看到优快云上有个分享个人技术栈的活动,虽然我不是一个正规的程序员,也不搞前端、后端这些,但我一直在优快云上通过写博客对我的学习进行总结,于是我突发奇想,不如我也写一下我的个人技术栈,针对机械臂控制入门的,因为我水平也不高,所以本文内容也许不够饱满,也不够准确,但

要恰饭得嘛 5856

判断一串字符中是否有回文串

//C++版#include //判断是否包含回文字符串,如有,返回回文起始位置;如没有,返回字符串长度 using namespace std; int find(char ch,char *str,size_t length) //查找str开始的字符串中第一个ch出现的位置,没找到返回-1 { for(int i=0;i<length;i++) {

书剑江山的博客 3331

华为手环实时心率数据导出到UWP项目中

hello大家好呀O(∩_∩)O最近在做毕设 其中有个小功能要用到实时心率数据。查找网上的资料发现只有小米手环的实时心率数据导出但是没有华为手环的,我试了华为手环但是并不能行得通哈哈哈。现在分享一下华为手环实时心率数据导出的代码。

apple_63713858的博客 1581

20. 回文串(非动态规划法)

给你一个字符串,问最少在字符串尾添加多少字符,可以使得字符串变为回文串。每组测试数据第一行是一个正整数N,表示字符串长度,接下来一行是长度为N的字符串,字符串中只有小写字母。以尾字符结尾的子串为回文串时,则可以添加s1.size()-s2.size()的字符使s1变为回文串。对于每组测试数据,输出一个非负整数:添加最少的字符数,可以使得字符串变为回文串。10%的数列元素个数N 1 ≤ N≤ 100000;20%的数列元素个数N 1 ≤ N≤ 10000;30%的数列元素个数N 1 ≤ N≤ 1000;

Ethrsu的博客 154

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

华为面试题: 没有回文串

【没有回文串】 回文串的定义:正读和反读都一样的字符串 现在已经存在一个不包含回文串的字符串,字符串的字符都是在英语字母的前N个,且字符串不包含任何长度大于等于2的回文串;请找出下一个字典序的不包含回文串的、字符都是在英语字母的前N个、且长度相同的字符串。如果不存在,请输出NO。示例1: 输入: 输出: 示例2: 输入: 输出:...

四库全书的酷 1513

深度学习工具包 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")

牛客网编程题

1.找出最大回文串的长度#include<iostream> #include<string> using namespace std; int main() { string s; cin >> s; int startk = -1; int endk = -1; int number=0; int maxnumber = -1; for (

daisyliudi的专栏 781

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

华为机试题85-最长回文子串

描述 给定一个仅包含小写字母的字符串,求它的最长回文子串的长度。 所谓回文串,指左右对称的字符串。 所谓子串,指一个字符串删掉其部分前缀和后缀(也可以不删)的字符串 数据范围:字符串长度1≤s≤350 进阶:时间复杂度:O(n) ,空间复杂度:O(n) 输入描述: 输入一个仅包含小写字母的字符串 输出描述: 返回最长回文子串的长度 示例1 输入: cdabbacc 复制输出: 4 复制说明: abba为最长的回文子串 解题思路: 首先我们要了解什么是回文字符串,可以

qq_47307864的博客 565
上一篇: Jzoj4437 线性代数与逻辑
下一篇: Jzoj4446 B
扩展的灰
博客等级 码龄12年 60粉丝 342原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值