sicily1137. 河床

河床问题,输入一段求不超过k的连续最长的一段 地理学家经常要对一段河流进行测量分析。他们从上游开始向下游方向等距离地选择了n个点测量水位深度,得到一组数据d1,d2,...dn。现要求找出一段河流中最大高低起伏不超过k的最长的一段。 例如 5 3 2 2 4 5 k=2 则最长的一段河床为4。 立即下载
//这道题目有点水,读懂题目,一次搜索,然后
//然后,标记好每一个位置的最大连续长度即可。。
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
    int n, k;
    int a[30009];
    cin >> n >> k;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
    }
    int b[30009];
    memset(b, 0, sizeof(b));
    b[1] = 1;
    int max = 1;
    for (int i = 2; i <= n; ++ i)
    {
        b[i] = 1;
        for (int j = i - 1; j >= i - b[i - 1]; -- j)
        {
            if (abs(a[j] - a[i]) <= k)
            {
                ++ b[i];
            }
            else
            {
                break;
            }
        }
        if (max < b[i])
        {
            max = b[i];
        }
    }
    cout << max << endl;
    //system("pause");
}
FLUENT二维河床冲刷UDF FLUENT二维河床冲刷UDF 希尔兹数 床面切应力 立即下载

相关推荐

河床演变宽深比计算程序

在河床演变分析中,河相系数是重要参数,这个程序可用来根据河床断面计算河床宽深比

Sicily 1137. 河床

找出最小值和最大值之差小于k的并且最长的那一段,注意n=1的情况 #include #include #include #include #include using namespace std; int arr[100000],a[100000]; int Max(int j){ sort(a,a+j); return (a[j-1]-a[0]); }//找出某一段

Lu的专栏 502

Ubuntu 24.04 安装 ROS2 Jazzy

手把手教你在Ubuntu24.04上安装JazzyROS2操作系统。

weixin_74185504的博客 1万+

YTU OJ 1960: 河床

Description 地理学家们经常要对一段河流进行测量分析。他们从上游开始向下游方向等距离地选择了n(n≤30000)个点测量水位深度。得到一组数据d1,d2,...,dn,回到实验室后数据分析员根据需要对数据进行分析,发掘隐藏在数据背后的规律。最近,乌龙博士发现某种水文现象与河床地势有关,于是他指示分析员要找到一段河流中最大高低起伏差不超过k(k≤100)的最长一段。这看似一个复杂的问题,...

mcp3128 557

win11一直弹出用户账户控制怎么解决

用户帐户控制简称UAC,是微软公司在其Windows Vista及更高版本操作系统中采用的一种控制机制。近期有部分Win11用户想要关闭UAC,但是不知道应该如何操作,对此下面我就教给大家操作方法,大家可以去尝试看看。...

xitongzhijia_abc的博客 5万+

从实习生到独立上手:我是如何用海思PQTool搞定IPC图像调试的

本文分享了从实习生到独立使用海思PQTool进行IPC图像调试的成长历程。通过工具搭建、核心参数调整和实战案例,详细介绍了如何高效解决图像质量问题,特别强调了ISP调试中的关键参数和实用技巧,适合刚入门的图像调试工程师参考。

weixin_33756596的博客 315

1137. 河床

Total: 5753 Accepted: 1736 Rating: 2.9/5.0(31 votes)Time Limit: 10sec Memory Limit:32MB Description 地理学家们经常要对一段河流进行测量分析。他们从上游开始向下游方向等距离地选择了n(≤30000)个点测量水位深度。得到一组数据d1,d2,……,dn,回到实验室后数据分析

stary_yan的博客 634

STM32F407 UART4串口DMA收发实战:告别频繁中断,用空闲中断+DMA搞定不定长数据

本文详细介绍了STM32F407 UART4串口结合DMA和空闲中断实现高效不定长数据收发的实战方案。通过DMA硬件级数据搬运和空闲中断智能帧检测,显著降低CPU占用率,提升通信效率,适用于工业传感器数据采集和智能设备通信场景。

weixin_42631411的博客 160

Sicily 1137 河床

求一个最长的连续区间满足其中的最小数和最大数之差不大于k,直接做就可以了。 #include #include using namespace std; int main() { int n,k,m,l,i,j; int a[30100]; int low,high; while ( cin >> n ) { cin >> k; for ( i=0;i

Detective_Xin的专栏 799

系统架构设计(以飞控系统、航电系统、机电管理系统、电子电气架构为例)

系统架构涉及对系统的结构和行为进行高层次的描述。它包括系统的组成部分、这些部分之间的关系、与外部环境的交互方式,以及满足特定功能和非功能性需求的方法。系统架构定义了系统的总体设计蓝图,指导系统的开发、集成、部署和维护。系统架构设计的目的是通过合理的结构和设计原则,确保系统能够高效、稳定、安全地运行,满足当前和未来的需求,同时具备良好的维护性、扩展性和可持续性。良好的系统架构不仅能够提高系统的开发效率和运行性能,还能降低长期的维护和运营成本,支持系统的持续演进和技术更新。

qq_41854911的博客 3061

基于Verilog的简易音乐节奏游戏设计

由于完整的Verilog代码实现一个简易音乐节奏游戏可能会相当冗长,并且需要针对特定的FPGA开发板和硬件接口进行详细设计,因此在这里我将提供一个简化的代码示例,以展示如何实现游戏的核心部分:状态机、时钟分频和按键扫描。2. **状态机设计**:游戏的核心逻辑通过状态机实现,状态机根据当前状态和输入信号(如按键信号)转移到下一个状态,并输出相应的信号(如音频信号)。1. **时钟分频**:由于FPGA的工作频率通常较高,而音频输出所需的频率较低,因此需要通过时钟分频器将FPGA的系统时钟降低到合适的频率。

Loving_enjoy的博客 766

sicily 1137 河床

线段树 题意: 给你一个n个元素的数组,和一个整数k.求一个符合以下条件的最大的区间 条件:区间里任意两个元素的差值不能超过k 数据范围: n 思路: 暴力的话枚举每个左端点,然后往右扫,维护最大值和最小值,扫到使得max-min>k的时候就停止掉.这样做的复杂度理论上是O(n2).不过这里好像可以水过 正确的做法是用线段树.考虑某个固定的左端点,那么右端点的下

ljhandlwt 477

RK3588 buildroot 制作的系统增加 docker 支持

RK3588 使用buildroot制作的系统添加 docker 和 docker-compose 的功能

荻夜的博客 1569

sicily 1137 河床 (二分分治)

  《计算机算法设计与分析》啃书中。。。    有点看不进书,就来刷个水题吧,刚开始看错题了还。    注意:是所有测量点相差均不大于di而不是相邻两点。。。 1 //1137.河床 2 #include <iostream> 3 using namespace std; 4 5 int max_length(int d[], int l, int ...

weixin_30535913的博客 109

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Sicily - 1137 河床 滑动窗口+优先队列 重庆一中高2018级竞赛班第十一次测试 2016.9.24 Problem 3

【问题描述】 地理学家们经常要对一段河流进行测量分析。他们从上游开始向下游方向等距离地选择n(n 最近,乌龙博士发现某种水文现象与河床地势有关,于是他指示分析员要找出一段河流中最大高低起伏差不超过K(1 【输入格式】 第一行包含两个整数N和K,分别表示测量点的个数和博士要求的最大水深度(也就是河床的地势差)。 第二行包含N个整数,表示从上游开始依次得到的水位深度di(1 【输出格式】

灬豪侠彡 632

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

sicily 1137

呵呵。。我当时看了就想用分治来做(类似归并排序),但是归并的时候想不到怎么处理,感觉如果真要处理就跟我下面的代码一样,下面的代码是看了ac的人数直接写的。。#include #include using namespace std; int k; int data[30000]; int n; int main() { while(cin >> n >> k) { for(int i = 0; i > data[i]; int _max = 0; for(int i =

alfredtofu的专栏 798

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

Sicily 1037

数据最多30000,暴力解法~一个一个枚举就好了 题目如下: Description 地理学家们经常要对一段河流进行测量分析。他们从上游开始向下游方向等距离地选择了n(≤30000)个点测量水位深度。得到一组数据d1,d2,……,dn,回到实验室后数据分析员根据需要对数据进行分析,发掘隐藏在数据背后的规律。最近,乌龙博士发现某种水文现象与河床地势有关,于是他指示他手下的分析员要找出一

我是质点的专栏 745

【复赛模拟试题】河床

【问题描述】   地理学家们经常要对一段河流进行测量分析。他们从上游开始向下游方向等距离地选择n(n<=30000)个点测量水位深度。得到一组数据a1,a2,…,an,回到实验室后数据分析员根据需要对数据进行分析,发掘隐藏在数据背后的规律。  最近,乌龙博士发现某种水文现象与河床地势有关,于是他指示分析员要找出一段河流中最大高低起伏差不超过K(1<=K<=100)的最长的一段。这看似一个简单的问题

细雨欣然 641
上一篇: sicily1146.采药
下一篇: sicily4086. 韩信点兵
程序与算法
博客等级 码龄15年 8粉丝 34原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值