POJ1989 The Cow Lineup 额,贪心??

赛灵思KV260视觉AI套件实战:从模型到边缘部署全流程解析 边缘计算与AI推理加速是当前嵌入式系统和物联网领域的关键技术。其核心原理在于将计算任务从云端下沉至网络边缘的设备端,通过专用硬件加速器(如FPGA、ASIC或NPU)执行神经网络推理,从而显著降低延迟、减少带宽消耗并提升数据隐私性。这一技术为实时性要求高的应用场景(如工业视觉检测、智能安防、自动驾驶等)提供了关键支撑。以赛灵思(Xilinx)的Zynq UltraScale+ MPSoC平台为例,其集成了ARM处理器与可编程逻辑,通过预置的深度学习处理器单元(DPU)为卷积神经网络提供高效INT8加速。开发 阅读详情

传送门


题目大意:
给出n个数组成的一个串,这n个数的范围是1~k,求出最短非子序列的串(这个串只能由1~k中的数字组成)


分析:
额(⊙o⊙)…不会
题解是这么写的:
从前往后扫描,把原串划分成若干个序列,使得这些序列满足包含所有的1~k的数字,并且至少有一个数字只出现过一次,答案就是序列个数+1


代码如下:

#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=100000+5,maxk=10000+5;
int n,k,a[maxn],ans;
bool vis[maxk];
inline int read(void){
    char ch=getchar();
    int f=1,x=0;
    while(!(ch>='0'&&ch<='9')){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
        x=x*10+ch-'0',ch=getchar();
    return f*x;
}
inline bool check(){
    for(int i=1;i<=k;i++)
        if(!vis[i])
            return false;
    memset(vis,0,sizeof(vis));
    return true;
}
signed main(void){
    n=read(),k=read(),ans=0;
    for(int i=1;i<=n;i++)
        a[i]=read();
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        vis[a[i]]=1;
        if(check())
            ans++;
    }
    printf("%d\n",ans+1);
    return 0;
}

by >o< neighthorn

在macOS上使用GitHub的超详细指南 GitHub:免费的远程仓库,可用来托管自己的开源项目。它利用了Git强大的克隆和分支功能,让我们参与别人的开源项目和让别人参与自己的开源项目变得简单高效。 阅读详情

相关推荐

Eureka自我保护机制

Eureka自我保护机制 默认情况下,当eureka server在一定时间内没有收到实例的心跳,便会把该实例从注册表中删除(默认是90秒),但是,如果短时间内丢失大量的实例心跳,便会触发eureka server的自我保护机制,比如在开发测试时,需要频繁地重启微服务实例,但是我们很少会把eureka server一起重启(因为在开发过程中不会修改eureka注册中心),当一分钟内收到的心跳数大量减少时,会触发该保护机制。可以在eureka管理界面看到Renews threshold和Renews(last

Soul_Ming的博客 547

POJ-1989(最短非子序列)

/*==========================================================*\ | 最短非子序列长度 | 题目描述:n个数字串,串中每个元素均是1……k之间的任意常数, | 求最小的s,使得长度为s的由数字1到k组成的某一个串不能在该主串的子串中找到 | 如:n=14,k=5中,主串为:{1 5 3 2 5 1 3 4 4 2 5 1 2 3}

famousDT的专栏 1745

告别OLE!Delphi操作Excel的3种轻量级方案横向评测(FlexCel/XLSReadWriteII/LibXL)

本文深入评测了Delphi操作Excel的三种轻量级方案:FlexCel、XLSReadWriteII和LibXL。通过技术架构、API设计、性能测试和实战案例的全面对比,帮助开发者选择最适合的工具,提升Excel文件处理效率,告别传统OLE方案的依赖和性能问题。

onion的博客 940

poj1989

题意:给定一个序列,求其最短非子序列的长度。 分析:我们把序列划分为若干个区间,每个区间都包含(1~k)这些数字。我们使划分的区间尽量多,方法就是从左到右一旦满足了包含所有字符,则立即停止该区间,从下一位开始一个新的区间。答案就是划分的区间数+1。 下面我们简单证明一下:对于一个有x个区间的序列,一定包含了所有长度为x的序列。因为,对于任意一个长度为x的序列,只需要依次在x个区间中取出其对应位...

weixin_33725272的博客 205

Remote ID的调制解调FPGA实现

Remote ID源于航空安全需求,例如在无人机密集区域实现设备跟踪和防碰撞。它类似于航空领域的ADS-B系统,但针对低空飞行器。Remote ID系统通常工作在特定频段(如2.4 GHz或5.8 GHz),通过无线链路广播数据包,包含设备ID、经纬度、高度和速度等信息。调制解调过程确保这些数据在噪声环境中可靠传输。例如,标准如ASTM F3411定义了Remote ID的协议框架,其中调制解调是关键物理层组件。

yulongfenghu的博客 1512

STGCN实战:从零构建PyTorch时空图卷积网络预测城市交通流

本文详细介绍了如何使用PyTorch从零构建时空图卷积网络(STGCN)进行城市交通流预测。通过将交通网络建模为图结构,并融合时间卷积与空间图卷积,STGCN能有效捕捉交通流的时空依赖性。文章提供了从数据预处理、核心模块(TimeBlock与STGCNBlock)搭建、模型训练到实战技巧的完整指南,帮助开发者快速掌握这一前沿的交通速度预测技术。

wasm7browser的博客 252

poj 1989 The Cow Lineup 最短非子序列问题

本题的关键是发现最短非子序列和长度为n的序列之间的关系,规律是在长度为n的排列中找出囊括1到k的排列的个数 num,那么长度为num的序列都是长度为n的子序列,因为都可以从num囊括1到k的排列中挑选出符合要求的数字组成长度为num的序列 然后最短非子序列的长度为num + 1 如题中所给示例  1 5 3 2 5 1 3 4 4 2 5 1 2 3          (1 5 3 2 5 1

必然中的偶然 1414

Tina Linux WiFi驱动移植避坑指南:以RTL8733bs为例,详解设备树、Kconfig与固件依赖

本文详细解析了在Tina Linux上移植RTL8733bs WiFi驱动的关键步骤与常见问题,涵盖设备树配置、内核依赖、固件加载及启动时序等核心环节。通过实战案例和排查清单,帮助开发者规避SDIO控制器配置、电源管理、GPIO极性等典型陷阱,确保驱动稳定运行。

weixin_29164185的博客 267

POJ 1989(双权值并查集)

Navigation Nightmare Time Limit:2000MS Memory Limit:30000K Total Submissions:8503 Accepted:3062 Case Time Limit:1000MS Description Farmer John's pastoral...

weixin_30436101的博客 164

k8s部署 普罗米修斯(Prometheus)监控

Prometheus是一个开源的服务监控系统和时序数据库其提供了通用的数据模型和快捷数据采集、存储和查询接口它的核心组件Prometheus服务器定期从静态配置的监控目标或者基于服务发现自动配置的目标中进行拉 取数据新拉取到啊的 数据大于配置的内存缓存区时,数据就会持久化到存储设备当中。

D2961953033的博客 3877

Vivado中怎么做set_input_delay约束

参考:https://forums.xilinx.com/t5/Timing-Analysis/Hold-violation-in-ISERDES/td-p/715121前言在STA中,要分析上游器件和FPGA之间的时序关系就得指定inputdelay。流程什么是inputdelay:约定上游芯片输出及时钟之间的关系。约束的目的就是看适配后的时序关系是什么样的。以下以源同步接口举例,...

小翁同学 6567

POJ1989 The Cow Lineup——贪心+扫描技巧

开始的时候没有想出算法,上网查题解,居然有人说这题是动态规划……无奈。偶然间看到了上海交大马融牛的解题表格:只有一句话,从前向后扫描。才知道这道题用到的只不过是一个贪心思想。 贪心思想: 把序列划分成尽量多的连续子序列,使得每一个连续子序列都满足如下条件: 1..k每个数字

这个诗人不懂浪漫 1219

LVGL(lv_canvas)

这篇文章介绍了LVGL图形库中的lv_canvas组件,主要内容包括: lv_canvas是一个绘图缓冲区对象,提供丰富的绘图API,可以理解为LVGL的"离屏画布"。 基本使用流程:创建缓冲区->创建canvas对象->设置缓存和尺寸->进行绘图操作。 详细列举了常用的绘图函数,如绘制线条、矩形、文字、图片等。 提供了示例代码展示如何创建画布并绘制一条红色线段。 介绍了canvas的典型应用场景,如动态波形绘制、自定义控件底图等。 对比了canvas与普通img的区别

m0_49476241的博客 1039

别再只认识Qm开头了!手把手教你用CID Inspector工具拆解IPFS内容地址

本文详细介绍了如何使用CID Inspector工具解析IPFS内容地址(CID),从Qm到bafy的版本演进,以及CID的结构和编码方式。通过实战案例和开发者技巧,帮助读者深入理解IPFS的内容寻址机制,提升在区块链和去中心化存储中的应用能力。

weixin_30333885的博客 374

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

POJ1989 The Cow Lineup——贪心+扫描法——Pku1989

开始的时候没有想出算法,上网查题解,居然有人说这题是动态规划……无奈。偶然间看到了上海交大马融牛的解题表格:只有一句话,从前向后扫描。才知道这道题用到的只不过是一个贪心思想。 贪心思想: 把序列划分成尽量多的连续子序列,使得每一个连续子序列都满足如下条件: 1..k每个数字都在这个子序列中出现过一次,并且至少有一个数字只出现过一次。 这样的子序列的个数+1就是答案 贪心思想证明: 要让...

weixin_34261415的博客 75

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

H-The Cow Lineup(POJ 1989)

The Cow Lineup Time Limit:1000MS Memory Limit:30000K Total Submissions:5367 Accepted:3196 Description Farmer John's N cows (1 <= N <= 100,000) are lin...

weixin_30794499的博客 114

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

poj 1989 & hdu 2712 & 洛谷5093 题解(贪心,思维,好题)

原题链接: poj hdu 洛谷 题意简述 给定一个序列,长度为n(&lt;=1e5)n(&lt;=1e5)n(<=1e5),所有数都在[1,k][1,k][1,k]范围内。请你在序列中找到一个长度最短的没有出现的子序列(不一定连续的那种)。 思路 题解里面有个奆佬是这么说的: 我们把原序列分组(一组是一段连续的子序列),一个组里包含[1,k][1,k][1,k]中的所有数...

LightningUZ的博客 347

poj-1989 The Cow Lineup

The Cow Lineup Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5587 Accepted: 3311 Description Farmer John’s N cows (1 <= N <= 100,000) are lined up in a row.Eac...

weixin_30608503的博客 161

POJ 1989 The Cow Lineup [dp]

题意: 给定一串长度=n,数字大小 问最短的不属于该序列子串的串长度为多少。这个串的数字都 思路: 说是dp,我觉得本质其实所找规律。 拿范例来说。 前8个数字已经使1,2,3,4,5都至少出现一次。 所以前8个数字可以归为一个集合。 然后再发现后6个数字也是1,2,3,4,5都至少出现了一次,也归为一个集合。 最后的答案数是集合数+1. 其实这种题目都是灵感很

Aszxqw 1202

POJ 1989

求最短非子序列的长度,找出这样的区间:该区间包含1—K的所有数字(可以有重复)。将原序列划分为N个这样的区间,则最终答案为N+1。原因是:长度为K的子序列可以由前K个区间中抽出一个数字组成,但对于K+1这样的子序列就找不到这样一个组合,因为少了最后一个数。就像例子里给的14 5 1 5 3 2 5 1 3 4 4 2 5 1 2 3 3。划分为【 5 1 5 3 2 5 1 3 4 】【 4 2

慕希颜 697

poj 1989 The Cow Lineup

感想:那个给我题目分类的人竟然说这个是DP,真心想求那位大神给我写个DP出来,也不看看这复杂度。 题意:给你n个数,让你找出最短的不包含在给出的这个序列中的一个排列(排列的数是1……K)。 思路:想DP就完了,就是一个找规律,找出里面包含几个1……k,然后再+1就完了。(这里是有顺序的,所以需要按照顺序去寻找) #include #include #include #define N 100

purevegetable 889

poj 1852 Ants 求蚂蚁最短全部掉落的时间

题目链接点击打开链接题解:最短时间:假设所有蚂蚁朝向比较近的端点,这种情况下,不会出现两只蚂蚁相遇的情况,而且也不可能在比此更短的时间内走到杆子的终点最长时间:两只蚂蚁相遇掉头返回可以换一种思维两只蚂蚁保持原样继续交错而过,所以只要求蚂蚁到杆子端点的最大距离#include&lt;cstdio&gt; #include&lt;iostream&gt; #include&lt;algorithm&g...

键盘上的青春 623

POJ 1989 贪心

题意: 思路: 从前到后扫一遍 如果k个数都出现过了 ans++ 从当前接着判断 最后答案就是ans+1 //By SiriusRen #include <cstdio> using namespace std; int n,k,vis[10050],cnt,ans=1,jy; int main(){ scanf("%d%d",&am...

weixin_34413103的博客 170

POJ 1989 The Cow Lineup G++ 巧妙

给出长度为N的数字序列,由K个不同数字组成。求由K个不同数字中的数字组成的,不是给出序列的子序列的,最短序列的长度。

woniupengpeng的专栏 397

The Cow Lineup(思维)

#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=1e4+100; bool st[N]; int main(){ int n,k;scanf("%d%d",&n,&k); int ans=0;int t=0; for(int i=1;i<=n;i++){ int x;scanf("%d.

qq_44866969的博客 206
上一篇: POJ 1664 放苹果 DP
下一篇: POJ 2279 Mr. Young's Picture Permutations......杨氏矩阵+钩长公式??
NeighThorn
博客等级 码龄11年 20粉丝 171原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址