字符串最小最大表示法(样题HDU-3374 String Problem)

字符串的最大/最小表示法 阅读详情

字符串最小最大表示法

爆肝模式开启o( ̄▽ ̄)ブ

  1. 有没有想过,如何求一个字符串的最大(最小)的表示方法,以下思维是从一个字符串中,找到最大的字母所在的位置,然后拼连成最大or最小的字符串。

  2. 我们先从一个简单的例子谈起吧,比方说ABCD,那我可以有几种形式表示呢?

    ABCD BCDA CDAB DABC

我们可以通过两个指针 X,Y来标记

其基本思路如下

令x=0,y=1
如果S[x] > S[y] x=y, y=x+1
如果S[x] < S[y] y++
如果S[x]==S[y] 设指针k,分别从x和y位置向下比较,直到S[x] != S[y]
如果S[x+k] > S[y+k] x=y,y=x+1
否则y++
返回x

但是

步子有点小,容易超时啊

这时候就应该改进了

令x=0,y=1
如果S[x] > S[y] x=y, y=x+1
如果S[x] < S[y] y++
如果S[x]==S[y] 设指针k,分别从x和y位置向下比较,直到S[x] != S[y]
如果S[x+k] > S[y+k] x=x+k
否则j++
返回x和y的小者

在比较中可以用char强制转int直接用scaII码对比,也可以单字符对比,看个人喜好了

下面用强制转码对比

//最小表示法
int get_minstring(char *s)
{
   int len = strlen(s);
   int i = 0, j = 1, k = 0;
   while(i<len && j<len && k<len)
   {
       int t=s[(i+k)%len]-s[(j+k)%len];
       if(t==0)
           k++;
       else
       {
           if(t > 0)
               i+=k+1;
           else
               j+=k+1;
           if(i==j) j++;
           k=0;
       }
   }
   return min(i,j);
}

//最大表示法
int get_maxstring(char *s)
{
   int len = strlen(s);
   int i = 0, j = 1, k = 0;
   while(i<len && j<len && k<len)
   {
       int t=s[(i+k)%len]-s[(j+k)%len];
       if(t==0)
           k++;
       else
       {
           if(t > 0)
               j+=k+1;
           else
               i+=k+1;
           if(i==j) j++;
           k=0;
       }
   }
   return min(i,j);
}

上例题

String Problem

HDU-3374
Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings:
String Rank
SKYLONG 1
KYLONGS 2
YLONGSK 3
LONGSKY 4
ONGSKYL 5
NGSKYLO 6
GSKYLON 7
and lexicographically first of them is GSKYLON, lexicographically last is YLONGSK, both of them appear only once.
Your task is easy, calculate the lexicographically first string’s Rank (if there are multiple answers, choose the smallest one), its times, lexicographically last string’s Rank (if there are multiple answers, choose the smallest one), and its times also.

Input

Each line contains one line the string S with length N (N <= 1000000) formed by lower case letters.

Output

Output four integers separated by one space, lexicographically fisrt string’s Rank (if there are multiple answers, choose the smallest one), the string’s times in the N generated strings, lexicographically last string’s Rank (if there are multiple answers, choose the smallest one), and its times also.

Sample Input

abcder
aaaaaa
ababab

Sample Output

1 1 6 1
1 6 1 6
1 3 2 3

题意

输出所给字符串的最大最小表示的起始位置和数量!

思路

我们可以用最大最小的公用模板求出位置,然后用kmp求出个数

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define MAXN 1000017
int Next[MAXN];
char str[MAXN];
int k;
void getNext( char T[],int len)
{
    int i = 0, j = -1;
    Next[0] = -1;
    while(i < len)
    {
        if(j == -1 || T[i] == T[j])
        {
            i++,j++;
            Next[i] = j;
        }
        else
            j = Next[j];
    }
}
int get_minstring(char *s)
{
    int len = strlen(s);
    int i = 0, j = 1, k = 0;
    while(i<len && j<len && k<len)
    {
        int t=s[(i+k)%len]-s[(j+k)%len];
        if(t==0)
            k++;
        else
        {
            if(t > 0)
                i+=k+1;
            else
                j+=k+1;
            if(i==j) j++;
            k=0;
        }
    }
    return min(i,j);
}
int get_maxstring(char *s)
{
    int len = strlen(s);
    int i = 0, j = 1, k = 0;
    while(i<len && j<len && k<len)
    {
        int t=s[(i+k)%len]-s[(j+k)%len];
        if(t==0)
            k++;
        else
        {
            if(t > 0)
                j+=k+1;
            else
                i+=k+1;
            if(i==j) j++;
            k=0;
        }
    }
    return min(i,j);
}
int main()
{
    while(scanf("%s",str)!=EOF)
    {
        int len = strlen(str);
        getNext(str,len);
        int tt = len - Next[len];
        int num = 1;
        if(len%tt == 0)
        {
            num = len/tt;
        }
        int posmin = get_minstring(str);
        int posmax = get_maxstring(str);
        printf("%d %d %d %d\n",posmin+1,num,posmax+1,num);
    }
    return 0;
}

如有不对的地方欢迎指正。

FreeRTOS笔记(十五)FreeRTOS总结 文章目录01 - 裸机和FreeRTOS区别1.1 - 裸机1.2 - FreeRTOS1.3 - 区别02 - 对FreeRTOS的感受03 - 推荐 上一文链接:FreeRTOS笔记(十四)[简] 软件定时器、事件组、任务通知 01 - 裸机和FreeRTOS区别   学完FreeRTOS,应该要自己总结一下FreeRTOS和裸机的区别,宏观上说,FreeRTOS是一个运行在裸机上的微内核,... 阅读详情

相关推荐

Silvaco TCAD | 从PIN到APD:高性能光电探测器的仿真设计与优化

本文详细介绍了使用Silvaco TCAD进行光电探测器仿真设计与优化的全过程,从基础的PIN结构到高性能APD的实现。通过实战案例和代码示例,展示了如何优化器件参数、实现雪崩效应以及进行高级仿真分析,帮助工程师提升光电探测器的量子效率和响应速度。

weixin_29218509的博客 427

【字符串】最小表示法

给定一个字符串 s 和一个整数 k。你可以从 s 的前 k 个字母中选择一个,并把它加到字符串的末尾。字符串 S 的最小表示为与 S 循环同构的所有字符串中字典序最小的字符串。返回 在应用上述步骤的任意数量的移动后,字典上最小的字符串。最小表示法是用于解决字符串最小表示问题的方法。当字符串 S 中可以选定一个位置 i 满足。则称 S 与 T 循环同构。...

文艺倾年的博客 1176

从零构建:如何用MATLAB打造你的第一个Stewart平台运动学仿真器

本文详细介绍了如何使用MATLAB从零构建一个六自由度Stewart平台运动学仿真器,涵盖基础理论、环境配置、运动学建模、动态轨迹规划和实时可视化实现。通过MATLAB的Robotics System Toolbox和Simulink等工具,读者可以掌握六自由度Stewart平台的逆运动学求解、正运动学求解及仿真系统集成,适用于飞行模拟器和精密定位等应用场景。

peach的博客 864

字符串的最大最小表示

又是要求循环字符串中最小字典序的串的位置,和最大字典序的串的位子 int Min_or_Max(bool Min,int len) { int i = 0, j = 1, k = 0, sub = 0; while (i { sub = str[(i + k) % len] - str[(j + k) % len]; if (sub == 0) k++; else { if

ACM之梦 841

YOLO26 无损剪枝:稀疏训练 + 结构化通道裁剪

YOLO26 无损剪枝链路:YOLO26s (7.2M) → 稀疏训练 30 epoch (L1 on BN gamma, lam=0.01) → 阈值剪枝 50% (gamma<quantile(0.5)) → 结构化重建 Conv+BN → 微调 10 epoch (lr=1e-4) → YOLO26n (1.9M, mAP50 0.808, 仅降 0.6%)。核心贡献:稀疏训练让 BN gamma 趋向二元分布 (近 0 或近 1), 剪枝阈值可直接取 median 自动 50% 压缩。

m0_64661770的博客 263

【运动规划算法项目实战】Artificial Potential Field算法(附ROS C++代码)

在机器人行业中,路径规划是一个关键的任务,它涉及到如何让机器人在复杂的环境中安全而高效地移动。人工势场算法(Artificial Potential Field Algorithm)是一种常用的路径规划方法,它借鉴了物理学中的势能概念,通过模拟力的作用来引导机器人的移动。本文将详细介绍人工势场算法的原理、在路径规划中的应用、算法优缺点以及代码实现。人工势场算法基于两种势场:斥力场和引力场。斥力场使机器人远离障碍物,而引力场将机器人吸引到目标位置。

xiewf的博客 1万+

最小表示法总结+例题

给一个字符串,如果这个字符串是环状的,它的字典序最小的表示方法是什么。 O(n)算法 与kmp相似,都是相同的不再比较。 i和j为两个不同的起点引领的长度为k的字符串 int n=strlen(s+1); for(int i=1;i<=n;i++) { s[n+i]=s[i]; } int i=1,j=2,k; while(i<=n&&j<=n) { ...

weixin_43819578的博客 691

Flutter:如何在Android中实现串口通信调试

本文介绍如何通过flutter_libserialport插件在Flutter中实现串口通信调试。

sg_knight的专栏 6098

字符串——字符串的最大最小表示法

字符串的最大最小表示法 感谢这篇博客:字符串的最小表示法 引言:一个长度为n的字符串可以将最后一位放在第一位,这样就有n种变形。如"bcaxe" 可以变成 :ebcax xebca axebc caxeb 这几种。 字符串的最大最小表示法,就是求着n种变形中的最大最小字典序的字符串,返回的值是第一个最大最小的字符串的起始字符位置,时间复杂度为O(n)。 思想:(最小表示法) 就是定义三个下标初始 ...

wxy2635618879的博客 1469

slew dreate,slew threshold与transition计算

​只看rise情况下,from pin取slew threshold10%-90%的区间,slew derate为1,计算得到transition为1.002e-10,to pin的slew threshold 为30%-70%,slew derate 0.5,从波形列表上取相近的值3.75e-10和8.75e-10,计算得到transition为(8.75e-10-3.75e-10)/0.5=1e-9,考虑精度和取值区间问题,基本符合工具计算的值,如下:​。如下示例,在.lib库中有定义以下内容。

m0_61544122的博客 793

Java SSH框架学习

Java SSH框架学习

私信可回答各种问题~ 1789

HDU 3374 String Problem(最大最小表示法 模板题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374Problem DescriptionGive you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can ...

1670

2026快手爬虫终极指南:JA4+指纹绕过+sign全逆向+AES响应解密(附可运行代码)

快手2026反爬破解实战指南 本文深入剖析快手2026年最新反爬体系,提供完整的破解方案: 四层防御体系:从传输层(JA4+指纹)、应用层(sign参数)、设备层到行为层,90%的爬虫在前两层即被拦截 JA4+指纹绕过:使用curl_cffi模拟Chrome 124的TLS指纹,完美匹配真实浏览器特征 sign参数逆向:通过动态调试提取加密逻辑,Python实现MD5签名算法,包含参数排序和盐值处理 响应解密:破解AES-GCM加密接口数据,完整还原响应内容 技术亮点: 使用curl-impersonate

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1802

HDU - 3374 String Problem 求字符串的最大最小表示法 并求循环次数

HDU - 3374 String Problem 题意: 给你一串字符,这串字符可以左移(将最前面一个字符放到字符串最后面)生成 strlen(s) 个字符串,求出其中字典序最小 和 最大 的字符串在原串的起始位置和出现的次数(如果存在多个最小或最大串,则输出rank值小的,即下标小的那个)。 输出:最小字符串起始位置 出现次数 最大字符串起始位置 出现次数 思路: ...

没有梦想何以远行 235

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

hdu 3374 String Problem (最大最小表示法)

http://acm.hdu.edu.cn/showproblem.php?pid=3374 SKYLONG 1 KYLONGS 2 YLONGSK 3 LONGSKY 4 ONGSKYL 5 NGSKYLO 6 GSKYLON 7 题意:输出的是最小字典序的编号,最小字典序个数,最大字典序编号,最大字典序个数 求有几个这样的字符串直接Kmp求得next数组就ok了, 然后

大太阳 786

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

HDU 3374 String Problem 字符串最大最小表示法 模板题

Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings: String Rank SKYLONG 1 KYLONGS 2 YLONGSK...

zhangjinlei321的博客 317

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

HDU 3374 String Problem(最小表示法·KMP)

题意  给你一个环形串  输出其最小表示法的首字母位置  最大表示法的首字母位置  以及和对应位置等价位置的个数 最小表示法指一个循环串以某一位开始时对应的串的字典序最小  这个串就是该循环串的最小表示法  先看一下求字符串最小表示法的过程  可以看2003年国家集训队论文集中周源的论文 令 p 表示字符串 s 的最小表示法的下标,  l = strlen(s)  s = s + s

Deng's site \# 1311

N - String Problem HDU - 3374(最大最小表示法模板)

String Problem HDU - 3374 题意:给你一个字符串,让你求他的循环串的最大最小的位置,以及出现次数。 分析:出现次数很好求了,你可想如果最大最小出现多次即存在循环串,才有可能有多个最大最小。然后就是最大最小表示法的模板存一下。 #include <iostream> #include <cstdio> #include <stack&g...

fighting_yifeng的博客 262

HDU 3374 String Problem (KMP+最大最小表示)

转载请注明出处,谢谢http://blog.youkuaiyun.com/acm_cxlove/article/details/7854526       by---cxlove 题目:输出最大最小表示是从哪一位开始,而且输出数量 http://acm.hdu.edu.cn/showproblem.php?pid=3374  数量好求,肯定是字符串的循环节,循环节可以直接通过KMP的Next数组得到

窝不是爱酱,喵~~~~ 4294

HDU-3374-String Problem(最小表示法, KMP)

链接: https://vjudge.net/problem/HDU-3374 题意: Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven string...

weixin_30294021的博客 204

hdu 3374 String Problem(KMP + 最小串)

题目链接:hdu 3374 String Problem 题目大意:给出一个,字符串,每次将最前一个字符放到最后,知道形成一周,然后按照每个字符串出现的先后排个名次,现在要求求出字典序最小的字符串和字典序最大的字符串为RANK几。并输出它们的出现次数,如果出现次数不只一次,那么输出RANK值较小的。 解题思路:KMP中的求最小串,然后用最小串去原字符串中求匹配数量。

不慌不忙、不急不躁 1422

HDU 3374 String Problem(最大最小表示法+kmp)

Time Limit:1000MS Memory Limit:32768KBDescription Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven s

2cm的专栏 490

HDU - 3374 String Problem 最小最大表示法+循环节

题目链接:https://cn.vjudge.net/problem/HDU-3374 题意:向左移动【0, len-1】次,形成的n个串,求最小和最大串的起始位置,和有多少个 题解:求数目的话,直接找最小循环节即可,最小最大串位置直接最大最小表示法找就可以了。 #include <bits/stdc++.h> using namespace std; const int N ...

还我笑颜 253

HDU 3374 String Problem (字符串最小表示法+KMP)

String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4951    Accepted Submission(s): 2014   Problem Description Give you a string ...

LSD20164388的博客 336

【代码超详解】HDU 3374 String Problem(最小 / 最大表示法 + KMP 求最小循环节长度,109 ms)

一、题目描述 二、算法分析说明与代码编写指导 最小表示法 KMP 三、AC 代码 法一(468 ms): #include<cstdio> #include<algorithm> #include<cstring> #pragma warning(disable:4996) using namespace std; template<class _Ty...

COFACTOR 245
上一篇: 字典树学习
下一篇: 对我影响极大的几位老师
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值