PAT甲级1133

用顺序表、单链表将负数移动到其他元素前面 1、 有一个整数顺序表L,设计一个尽可能高效的算法将所有负整数的元素移到其他元素的前面,并给出算法的时间和空间复杂度。例如,L=(1,2,-1,-2,3,-3,4),移动后L=(-1,-2,-3,2,3,1,4)。例如,L=(1,2,-1,-2,3,-3,4),移动后L=(-1,-2,-3,1,2,3,4)。 阅读详情

PAT甲级1133

题目大意:给定一个链表以及一个数K,首先将链表中所有负数放在前面,其次从0到k之间的数(包括两个端点)接在后面,最后把大于k的数全部串在后面。所有操作保证数字的相对位置不变。
开辟data数组合next数组分别存放数据和下一个节点的地址,做三次循环处理,最后输出即可。注意这里链表当中有可能有无用数据,不能按照n所给输出,要统计总共多少有效数字(倒数第二个测试点)。

#include <iostream>
#include <vector>
#include <algorithm>
#define MAXN 1000005
using namespace std;

int data[MAXN],Next[MAXN],adjust[MAXN];
int main(){
	int start,n,k,address,cnt=0;
	scanf("%d%d%d",&start,&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&address);
		scanf("%d%d",&data[address],&Next[address]);
	}
	int start2=start,pre,tmp=start;
	bool flag=false;
	for(int i=0;i<n;i++){
		if(data[tmp]<0){
			if(flag==false){
				flag=true;
				start=tmp;
				pre=start;
			}
			else{
				adjust[pre]=tmp;
				pre=tmp;
			}
		}
		cnt++;
		tmp=Next[tmp];
		if(tmp==-1) break;
	}
	tmp=start2;
	for(int i=0;i<n;i++){
		if(data[tmp]<=k&&data[tmp]>=0){
			adjust[pre]=tmp;
			pre=tmp;
		}
		tmp=Next[tmp];
		if(tmp==-1) break;
	}
	tmp=start2;
	for(int i=0;i<n;i++){
		if(data[tmp]>k){
			adjust[pre]=tmp;
			pre=tmp;
		}
		tmp=Next[tmp];
		if(tmp==-1) break;
	}
	tmp=start;
	for(int i=0;i<cnt;i++){
		if(i!=cnt-1)
			printf("%05d %d %05d\n",tmp,data[tmp],adjust[tmp]);
		else printf("%05d %d -1\n",tmp,data[tmp]);
		tmp=adjust[tmp];
	}
	system("pause");
	return 0;
}

100天精通Python(爬虫篇)——第118天:selenium自动化操作浏览器基础大总结 一、Selenium框架环境搭建 1. 下载模块 2. 安装浏览器驱动WebDriver 二、基础操作 1. 打开浏览器 2. 无界面模式 3. 元素定位 4. 元素操作 5. 前进后退 6. 执行js 7.页面等待 隐式等待(常用) 显式等待(了解) 三、进阶操作 1. 使用代理ip 2. 修改请求头 3. 隐藏指纹特征..................... 阅读详情

相关推荐

海外跨境电商商城源码-进出口电商平台网站-多语言多商户平台

我们的海外跨境电商系统源码还包括各种功能模块,如用户管理、商品管理、订单管理等。支付管理:与主流支付平台(如Stripe、PayPal等)的集成,支持多种支付方式;订单管理:创建订单、支付订单、取消订单等操作,以及订单状态查询和历史记录;购物车管理:添加商品到购物车、查看购物车、修改购物车中的商品数量等操作;商品管理:商品信息录入、编辑、删除等操作,以及商品分类和搜索功能。客服管理:在线咨询、投诉处理等功能,提供更好的用户服务。用户管理:注册、登录、忘记密码、个人资料。# 检查电子邮件地址是否有效。

柏诣科技的博客 2657

数据结构 将链表中所有负数放置正数前面

#include &lt;iostream&gt; using namespace std; #define max 50 typedef int ElemType; typedef struct Lnode { ElemType data; struct Lnode * next; }LinkNode; void listcreat(LinkNode *&amp;l, Elem...

qq_41094265的博客 5107

Qt6.8.0(win64)安装教程

启动 Visual Studio 2022 Community,选择 “继续但无需代码” 运行,然后打开Option设置,Add一条版本配置,Location 选择 D:\Qt\6.8.0\msvc2022_64\bin\qmake,点击确定。我是win11系统,所以选择windows版,下载路径二选一即可。方案1:默认情况下,额外勾选图中两个组件(总共40多G)方案2:按图中自定义勾选组件(总共5.8G)选择Custom Installation。我选的方案2,总共5.81G。

D4G1TIAO的博客 9067

将所有负数移动到开头所有正数移到结尾

题目 给定一个整数数组 nums,数组中有正数也有负数,将负数移动到开头,正数移动到结尾 要求:一次遍历。 示例: 给定 nums = [-2, -7,5,9,-10, 11, -15] 返回 [-2, -7, -10, -15, 5, 11, 9] 解题思路 设置一个进位值j,来保存一个正数的值,跟随i进行遍历移动,当出现nums[i]小于0时,0也就是分水岭,进行nums[i]与nums[j]置换。 这里使用了 快速置换的方法 [a,b]=[b,a]; ES6的新方法 省去了设置temp的中间值

破茧 1989

图像调整亮度饱和度 c语言,【C#/WPF】调节图像的HSL(色相、饱和度、明亮度)...

先说概念:HSL是一种描述颜色的方式(其他颜色描述方式还有大家熟悉的RGB值)。HSL三个字母分别表示图像的Hue色相、Saturation饱和度、Lightness明亮度。需求:制作一个面板,包含三个滑动条,拖动滑动条可以修改目标图片的HSL值。即模仿PS中类似的功能,如下图:方案一:遍历所有像素点,修改每个点的HSL值。前台界面:一个Image控件显示目标图片,一个Button按钮点击一下降低...

weixin_39935777的博客 1154

记录rk3588 在Linux 6.1内核版本声卡 bug。

rk3588 Audio bug

Yongheng6的博客 855

在顺序存储模式下将所有的负数放到正数前面的三种算法

test1的时间复杂度最高,test2的时间复杂度优于test1,test3的时间复杂度最小,所用的时间最少/************************************test1**********************/ //程序功能:在顺序存储模式下将所有的负数放到整数前面 #include using namespace std; /* *算法描述:找到负数并用临时变量存上,

caidadong的专栏 5802

GD32H7 SPI驱动实战:手把手教你用SPI3连接外部Flash(W25Q128)并实现读写

本文详细介绍了基于GD32H7系列MCU的SPI3接口驱动W25Q128外部Flash的全流程开发指南。从硬件设计、引脚配置到SPI3外设深度配置,再到底层通信函数实现和高级功能优化,提供了完整的解决方案。特别针对高速读取、DMA传输和信号完整性等关键环节进行了优化,确保系统在-40℃~85℃范围内稳定工作。

weixin_28729205的博客 379

正负数排列(用链表和数组实现)

【问题描述】 一个未排序整数数组,有正负数,重新排列使负数排在正数前面。并且要求不改变原来的正负数之间相对顺序。比如输入1、7、-5、9、-12、15,输出-5、-12、1、7、9、15。 【基本要求】 多种算法解决这个问题,并探讨有无时间复杂度O(N),空间复杂度O(1)的算法。 public class ch01 { public void operate(int maxSize,int[] numbs){ int j=0; .

m0_57492901的博客 2995

【图文步骤】EC-Engineer部分操作详细步骤

EC-Engineer部分功能详细使用手册

weixin_42212468的博客 6164

从零开始用 C# 打造工业级上位机系统:完整项目实战

本文介绍了一个基于C#开发的工业级上位机系统项目。该系统采用分层架构设计,包含通信、数据采集、UI展示、告警日志等模块,支持Modbus协议和串口通信。文章详细阐述了系统架构设计、关键模块实现(如Modbus通信封装、实时数据采集、告警系统等)以及性能优化策略。该项目已在实际工控场景中稳定运行超过1年,具备良好的可扩展性和稳定性,适合有一定C#基础的开发者参考学习工业软件开发实践。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1367

PAT【甲级】1133

题目链接:PAT【甲级】1133 题目简述:以整数的形式给定链表各节点的位置,让我们按一定形式规则输出新链表。 #include<bits/stdc++.h> using namespace std; unordered_map<int, int> indice; struct node{ int address, value, next; }; vector<node> ans, t1, t2; int main(){ int as, n, k;

qq_41375322的博客 245

PostgreSQL 异常排查:读取流时发生异常 (x80004005)

通过以上步骤,您应该能够解决在 .NET Core 中与 PostgreSQL 数据库进行交互时出现异常 (x80004005) 的问题。确保数据库连接正确,查询语句准确,并使用兼容的驱动程序版本。如有必要,可以捕获异常并查看详细的错误信息,以便更好地排查问题。在使用 .NET Core 开发应用程序时,如果在与 PostgreSQL 数据库进行交互时遇到异常,例如在读取数据流时发生异常 (x80004005),我们需要进行排查和修复。另外,还可以尝试捕获异常并打印异常信息,以便更好地了解问题所在。

XwlyVue的博客 1621

pat甲级1133 1133 Splitting A Linked List (25分)

文章目录pat甲级1133 1133 Splitting A Linked List (25分)1. 20分代码(最后一个点代码)2.正确代码3.总结 pat甲级1133 1133 Splitting A Linked List (25分) 1. 20分代码(最后一个点代码) #include <iostream> #include <vector> #include <unordered_map> using namespace std; struct node {

qq_44992782的博客 249

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

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

PAT甲级1133 Splitting A Linked List:[C++题解]链表

刷题

阿正的梦工坊 402

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

PAT甲级 1133

1133 Splitting A Linked List (25 分) Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-negatives, and all the values i...

YOUN尔 409

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

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

PAT甲级A1133

1,题目 点我 ^ _ ^ 2注意点 注意倒数第二测试点可能出现不在链表中的结点,因此输出时不能固定输出N个,而是num_result个结点。 for(int i=0; i<num_result; ++i) { if(i==num_result-1) { printf("%.5d %d -1\n",result[i].Address,result...

qq_29006825的博客 227

PAT 甲级 1133 PAT Ranking 个人错误总结

链表题,每次都是一个套路。。 #include<bits/stdc++.h> using namespace std; struct node{ int add; int data; int next; }linklist[100000]; int main(){ int add,n,k; cin>>add>>n>>k; int step,num,temp; for(int i=0;i<n;i++){ cin>>step&g

☁的博客 195

PAT——1133 Splitting A Linked List 甲级

1133 Splitting A Linked List题目题意代码解析注意AC代码参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/994805346776760320 题意 给出链表和K值,按要求先输出小于0的节点,然后输出0到k之间的节点,最后输出大于0的节点 代码解析 通过map<int,node>储存节点信息,然后按照链表的顺序判断当前节点属于哪一部分,并放入对应的ans向量中,最后按要求输出即可 注意 不

ljhsq的博客 156

PAT甲级 1133 Splitting A Linked List

浙江大学PAT题目解答内容. Contribute to ZouJiu1/PAT development by creating an account on GitHub.GitHub - ZouJiu1/PAT: 浙江大学PAT题目解答内容。

邹九的个人博客 200

PAT 甲级 1133  Splitting A Linked List

1133 Splitting A Linked List (25 point(s)) Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-negatives, and all the v...

漫浸天空的雨色的备忘录~ 794

【PAT甲级 - C++题解】1133 Splitting A Linked List

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 483

1133 Splitting A Linked List-PAT甲级

Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-negatives, and all the values in [0, K] appear before all those grea...

amf12345的博客 173

PAT甲级1133解题报告

1133 Splitting A Linked List (25 point(s)) Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-negatives, and all the v...

TateBrwonJava的博客 589

PAT甲级题目1133Splitting A Linked List

题目大意: 给出一个单链表,根据数据不同,<0,0>=0&&<=k,>k,按照这个顺序输出。 代码: #include <cstdio> #include <algorithm> using namespace std; const int maxn = 100010; struct Node { int data; int address; int next; int flag; int num; }n

weixin_43801993的博客 140

PAT甲级-1133 Splitting A Linked List

链表的遍历,测试点5段错误的处理

weixin_74092648的博客 863
上一篇: PAT甲级1130
下一篇: PAT甲级1134
zerohawk
博客等级 码龄8年 3粉丝 78原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值