Jzoj4788 序列

ArcGIS坐标系实战:从北京54到CGCS2000的完整转换指南(附常见报错解决方案) 本文提供了在ArcGIS中将北京54坐标系数据转换为CGCS2000坐标系的完整实战指南。文章深入剖析了地理坐标系与投影坐标系的区别,详细讲解了转换前的数据诊断、参数获取方法,并分步演示了创建自定义地理变换和执行投影工具的核心操作流程。同时,针对数据错位、转换失败等5种常见报错现象,给出了具体的排查思路与解决方案,帮助GIS从业者高效、准确地完成这一关键的数据处理任务。 阅读详情

题意:给你a,b两个序列,每次可以在区间[l,r]对每个数加一,求最少的步数使a变成b

注意,整个过程都是在mod 4的意义下的,a,b所有元素的值都在[0,3]之间

我们可以先考虑不存在Mod 4 的情况

我们假设di=max(0,bi-ai)

那么显然,对于一个位置i,我们需要将其操作max(0,di)次

考虑从1开始,我们设f[i]表示将1~i的d清零所需要的最小次数

显然,f[1]=d[1],f[i]=f[i-1]+max(0,d[i]-d[i-1]) (其实这是一个差分的经典应用)

现在我们来考虑Mod 4 的情况,由于有Mod 4 的影响,我们可以将一系列的d[i]变为d[i]+4k

这样在一种情况下会减小答案

若有i<j使得 d[i]-d[i-1]+4<d[j]-d[j-1] 那么,我们就可以将整个[i,j-1]的d都加上4

这样答案就可以减少(d[i]-d[i-1]-dj+dj-1+4)

实际上,我们只需要维护d[i]-d[i-1]=-2和-3的个数即可(-1+4=3 0+4=4显然都不可能)

每次都贪心地去取就可以

#pragma GCC optimize("O3")
#pragma G++ optimize("O3")
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,a[1000010],T;
int aim(){
	scanf("%d",&n); int cnt[4]={0},ans=0;
	for(int i=1;i<=n;++i) scanf("%d",a+i);
	for(int x,i=1;i<=n;++i){
		scanf("%d",&x);
		a[i]=(x-a[i]+4)&3;
	}
	for(int i=1;i<=n;++i) ans+=max(0,a[i]-a[i-1]);
	for(int i=2;i<=n;++i){
		int j=a[i]-a[i-1];
		if(j>0){
			if(cnt[1] && j>1){
				--cnt[1];
				++cnt[j];
				ans-=--j;
			} else if(cnt[2] && j>2){
				--cnt[2];
				++cnt[j];
				ans-=j-2;
			}
		} else ++cnt[j+4];
	}
	printf("%d\n",ans);
}
int main(){ for(scanf("%d",&T);T--;aim()); }

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

相关推荐

PCA9548实战:从硬件连接到Linux驱动的I2C扩展全解析

本文详细解析了PCA9548 I2C多路复用器从硬件连接到Linux驱动配置的全过程。涵盖硬件引脚连接、电源去耦、地址选择等关键设计要点,以及Linux驱动加载、设备树配置和应用层编程技巧,帮助开发者高效实现I2C总线扩展。

weixin_28726391的博客 414

jzoj4788 序列

题目给定序列A,B,每一次操作可以让A的i~j这个区间内+1%4,求多少次操作才能让A达到B先求出对于第i个位置从Ai−>BiAi->Bi要做多少次,记作DiDi 如果不考虑模的话,这题就是一个经典的粉刷问题, Ans=∑Di−Di−1|(Di>Di−1)Ans=\sum{D_i-D_{i-1}|(Di>D_{i-1})} 然后我们再考虑模,如果操作次数+4对正确性影响不大,那么我们什么时候才

一位蒟蒻的小博客 610

学Simulink--基于风力发电系统的场景实例:海上风电场在复杂海况下的动态响应仿真

本实例将创建一个针对海上风电场在复杂海况下的动态响应模型。该模型不仅考虑了不同风速条件的影响,还引入了波浪和水流对风机塔架及基础结构的影响。通过仿真验证系统的有效性,并探索最佳控制参数设置以提高整体性能和稳定性。本教程展示了如何在Simulink中实现一个海上风电场在复杂海况下的动态响应仿真模型,并分析其性能。通过这种方式,我们不仅可以验证所提出的技术手段在提高海上风电场稳定性和效率方面的有效性,还能进一步探索优化参数以适应特定的应用场景。

xiaoheshang_123的博客 170

【jzoj4788】【序列】

题目大意解题思路显然没有模的时候,后一个减前一个差分,正值加起来即为答案。考虑将一个区间加4,左端点的差分值加4,后端点的后一个的差分值减4,而只有正值对答案有贡献。将前面的差分值用桶存起来,枚举右端点,如果是正值则查找前面的差分值,看是否能通过操作使答案减少。code#include<set> #include<cmath> #include<cstdio> #include<cstring> #

inklutcuah’s blog 591

抓包工具:Fiddler下载、安装、使用 教程

文章目录抓包工具:Fiddler下载、安装、使用 教程一、Fiddler 下载二、Fiddler 安装三、Fiddler 使用3、Statistics 请求的性能数据分析4、Inspectors 查看数据内容5、AutoResponder 允许拦截指定规则的请求6、Composer 自定义请求发送服务器7、Filters 请求过滤规则8、Timeline 请求响应时间9、Fiddler 设置解密HTTPS的网络数据10、Fiddler 内置命令与断点 抓包工具:Fiddler下载、安装、使用 教程 Fidd

Sumarua的博客 17万+

【NOIP2016提高A组模拟9.17】序列

DescriptionInputOutputSample Input1 5 2 1 3 0 3 2 2 0 1 0Sample Output1Data Constraint然后我们再考虑模,如果操作次数+4对正确性影响不大,那么我们什么时候才需要让某个地方再做4次以达到答案减小的目的呢,不难发现就是这种情况 如果这样的话我们的代价其实就是 左右两边的和 减去 中间的 (假设中间的是相同高度

liangzihao1的博客 647

7.26华为OD机试真题 新系统 - 炸弹人的雷区数量 (Java/Py/C/C++/Js/Go)

7.26华为OD机试真题 新系统 - 炸弹人的雷区数量 (Java/Py/C/C++/Js/Go)

算法大师! 808

【JZOJ4788】序列

【JZOJ4788】题解

sadnohappy 596

RK3588网卡出现丢包或者带宽不足的问题验证排查

注意除了有最大的TCP数据接收缓冲,还有/proc/sys/net/core/wmem_max — 最大的TCP数据发送缓冲可以调整,这里暂时没用到,针对具体需要可适当调整。比如把ethx接口中断从默认的cpu0迁移到其它cpu,例如将eth0中断234移到cpu7 (10是16进制, cpu0 =3588的cpu有8个核,4个A55(小核)+4个A76(大核),可以找到对应中断 将中断从默认cpu0核切到cpu7。tcp_rmem:单位是字节,接收缓存区大小,缓存从对端接收的数据,后续会被应用程序读取。

Android/Linux驱动开发传帮带学习,让驱动入门门槛更低! 2034

Python爬虫实战:携程旅游攻略爬取全流程解析(动态接口+反爬破解+异步爬取)

本文介绍了携程旅游攻略的爬取全流程,涵盖静态和动态页面抓取、异步请求、高级反爬策略以及数据存储和简单分析。增加用户评论和评分抓取结合NLP分析攻略文本情感与关键词建立旅游推荐系统自动化代理IP池和验证码识别模块。

2201_76125261的博客 2040

[Jzoj] 3019. 序列和

题目大意 NNN个数排成一个环,请选出不超过KKK段的连续的数,段与段间不能重叠,且 使得选出的数和最大 题目解析 DPDPDP 设f[i][j][0/1]f[i][j][0/1]f[i][j][0/1]表示第iii个数第jjj段选或不选 f[i][j][0]=max(f[i−1][j][0],f[i−1][j][1])f[i][j][0]=max(f[i−1][j][0],f[i−1][j][1...

AAA_Ljw 195

CloudCompare二次开发(1)——获取指定高程的所有点

使用CloudCompare插件实现获取点云数据中指定高程的所有点。

点云侠的博客 4737

JZOJ4788. 序列

题目大意 给定两个长度为n的序列A,B。 每次操作,选择A中的一个区间加上1,再对4取模。 求把A变成B的最小操作次数。 T组数据。 Data Constraint n≤100000

Akakii的博客 892

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

【JZOJ 4788】 序列

Description Analysis首先求出每个位置的目标移动次数(mod 4) 比赛时想到了很好的思路,因为时间不够没有继续想下去。 后来我和xhm沿着这个想法,并最终想到了正解,同时也是samjia2000大神的方法。 首先对序列做差分,a[i]-=a[i+1] 不考虑升高4,答案为∑max(0,a[i]−a[i−1])\sum max(0,a[i]-a[i-1]) 一次升高操作

LYD729 669

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

【JZOJ 4788】序列

Solution把题目抽象一下,就变成了求序列中,每个点可以上升4,要使下降的总和最小, 首先,每个点可以上升多次!!! 当一个区间整体上升的时候,影响的就只有开头和结尾,如果要使答案减小,就要符合: ai−1−ai>aj+4−aj+1a_{i-1}-a_i>a_j+4-a_{j+1} 于是我们可以贪心的做,用did_i表示不等式后面的值等于i的位置有多少个, 每次直

1144

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

[jzoj 4788] 序列 {贪心/桶}

题目 解题思路 我们设d[i]表示a[i]要经过多少次操作后才可到达b[i],设c[i]=d[i]-d[i-1]。那么最朴素的想法答案ans=∑ni=1Max(0,c[i])。但这只是每个数都不会超过自己d[i]的情况,我们还要考虑假设某个数被某个区间包含,后来又多做了4次再次返回自已要求值的情况。显然对于现在的某段区间[i,j],它多做了4次会使c[j]-4,使c[i]+4,那么我们再回想...

Nowed 417

【差分 贪心】JZOJ_4788 序列

题意 思路 求出aia_iai​表示还需多少才能转换成bib_ibi​,把它差分。 如果加的数不超过444,那么答案就为∑i=1nmax(0,ai)\sum_{i=1}^{n}max(0,a_i)∑i=1n​max(0,ai​)。 否则如果让区间(l,r](l,r](l,r]加上4,即al−4,ar+4a_l-4,a_r+4al​−4,ar​+4,那么就要使ar+4&lt;ala_r+4...

GOODPLACE 381

JZOJ 4788. 序列

差分

Luckfort 604

NOIP提高组【JZOJ4788】序列

DescriptionData Constraint我们设d[i]表示a[i]要经过多少次操作后才可到达b[i],设c[i]=d[i]-d[i-1]。那么最朴素的想法答案ans=∑ni=1Max(0,c[i])\sum^{n}_{i=1}{Max(0,c[i])}。但这只是每个数都不会超过自己d[i]的情况,我们还要考虑假设某个数被某个区间包含,后来又多做了4次再次返回自已要求值的情况。显然对于现在

dance in th dark的博客 637

[JZOJ4788] 【NOIP2016提高A组模拟9.17】序列

题目 描述 题目大意 一个序列,每次可以使一段区间内的所有数加一(模四)。 问最少的操作次数。 思考历程 一看这题目,诶,这不就是那道叫密码锁的题目吗? 然后随便打一打,样例过了,就再也没有思考这一题。 正解 其实我的想法完全错了。 因为这题只能加,不能减啊! 于是就得考虑另一个方法。 题目可以转成这样的问题:给你一个数列,你可以预先给其中的数加四,然后每次对一个区间进行减一操作,问最...

A1847225889的博客 390

Jzoj P4788 序列___差分+贪心

题目大意: 分析: 设numinum_inumi​表示从aia_iai​到bib_ibi​至少需要操作多少次(第一次到bibibi所需次数) 对numinum_inumi​从后往前进行差分,di=numi−numi+1d_i=num_{i}-num_{i+1}di​=numi​−numi+1​ 那么我们可以发现,对于将所有的numinum_inumi​都变成000(aaa序列变成bbb序列),所...

生如夏花之绚烂 303

jzoj4788-[NOIP2016提高A组模拟9.17]序列【差分,贪心】

正题 题目大意 一个序列AAA可以每次选择一段区间(Ai+1)%4(i∈[l..r])(A_{i}+1)\%4(i\in [l..r])(Ai​+1)%4(i∈[l..r])。求最少次数使其变成BBB序列。 解题思路 先计算出每个数字最少加多少可以变成目标数字记录入aaa数组。 然后若不考虑一个数要取模多次的话答案就是 ∑i=2nmax⁡{ai−ai−1,0}\sum_{i=2}^n \max...

QuantAsk 618

JZOJ 4788. 【NOIP2016提高A组模拟9.17】序列

233题目:题意:分析:代码: 题目: 传送门 题意: 给出AAA、BBB两个序列,有将l—rl—rl—r区间内每个数先+1+1+1再%4\%4%4的操作,求将AAA变为BBB所要的最少步数 分析: 先出去模数操作,那么就是一道简单的差分约束,答案为∑i=1np[i]−p[i−1]\sum_{i=1}^np[i]-p[i-1]∑i=1n​p[i]−p[i−1] 对于有模数时,我们考虑到对于区...

qq_35786326的博客 375
上一篇: 一些基础算法的模板(持续更新)
下一篇: Jzoj4789 货物运输
扩展的灰
博客等级 码龄12年 60粉丝 342原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址