PAT甲级1133解题报告

2020年9月PAT甲级满分必备刷题技巧 这份技巧帮你一网打尽所有的要点 阅读详情

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 values in [0, K] appear before all those greater than K. The order of the elements inside each class must not be changed. For example, given the list being 18→7→-4→0→5→-6→10→11→-2 and K being 10, you must output -4→-6→-2→7→0→5→10→18→11.

Input Specification:

Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (≤10​5​​) which is the total number of nodes, and a positive K (≤10​3​​). The address of a node is a 5-digit nonnegative integer, and NULL is represented by −1.

Then N lines follow, each describes a node in the format:

Address Data Next

where Address is the position of the node, Data is an integer in [−10​5​​,10​5​​], and Next is the position of the next node. It is guaranteed that the list is not empty.

Output Specification:

For each case, output in order (from beginning to the end of the list) the resulting linked list. Each node occupies a line, and is printed in the same format as in the input.

Sample Input:

00100 9 10
23333 10 27777
00000 0 99999
00100 18 12309
68237 -6 23333
33218 -4 00000
48652 -2 -1
99999 5 68237
27777 11 48652
12309 7 33218

Sample Output:

33218 -4 68237
68237 -6 48652
48652 -2 12309
12309 7 00000
00000 0 99999
99999 5 23333
23333 10 00100
00100 18 27777
27777 11 -1

题目大意:将一个链表分成三个部分,负数,正数但不大于k,大于k的数三个部分,依次输出

解题思路:遍历链表然后分别放进三个容器,按照各自容器尺寸随便搞一搞输出一下就好了。

#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<list>
#include<climits>
#include<queue>
#include<cstring>
#include<map>
#include<stack>
#include<string>
using namespace std;
struct node {
	int address;
	int key;
	int next;
}s[100005];
vector<node> res1;
vector<node> res2;
vector<node> res3;
map<int, int> b;//记录add-key
map<int, int> c;//记录add-next
int main()
{
	int start, n, k;
	scanf("%d %d %d", &start, &n, &k);
	for (int i = 0; i < n; i++) {
		node cur;
		scanf("%d %d %d", &cur.address, &cur.key, &cur.next);
		b[cur.address] = cur.key;
		c[cur.address] = cur.next;
	}
	while (start != -1) {
		node cur;
		cur.address = start;
		cur.key = b[start];
		cur.next = c[start];
		if (b[start] < 0) {
			res1.push_back(cur);
		}
		else if (b[start] >= 0 && b[start] <= k) {
			res2.push_back(cur);
		}
		else {
			res3.push_back(cur);
		}
		start = cur.next;
	}
	if (res1.size() != 0) {
		for (int i = 0; i < res1.size(); i++) {
			if (i != res1.size() - 1) {
				printf("%05d %d %05d\n", res1[i].address, res1[i].key, res1[i + 1].address);
			}
			else {
				printf("%05d %d ", res1[i].address, res1[i].key);
			}
		}
		if (res2.size() == 0 && res3.size() == 0) {
			printf("-1\n");
		}
		else if (res2.size() == 0 && res3.size() != 0) {
			printf("%05d\n", res3[0].address);
			for (int i = 0; i < res3.size(); i++) {
				if (i != res3.size() - 1) {
					printf("%05d %d %05d\n", res3[i].address, res3[i].key, res3[i + 1].address);
				}
				else {
					printf("%05d %d -1\n", res3[i].address, res3[i].key);
				}
			}
		}
		else if (res2.size() != 0 && res3.size() == 0) {
			printf("%05d\n", res2[0].address);
			for (int i = 0; i < res2.size(); i++) {
				if (i != res2.size() - 1) {
					printf("%05d %d %05d\n", res2[i].address, res2[i].key, res2[i + 1].address);
				}
				else {
					printf("%05d %d -1\n", res2[i].address, res2[i].key);
				}
			}
		}
		else if (res2.size() != 0 && res3.size() != 0) {
			printf("%05d\n", res2[0].address);
			for (int i = 0; i < res2.size(); i++) {
				if (i != res2.size() - 1) {
					printf("%05d %d %05d\n", res2[i].address, res2[i].key, res2[i + 1].address);
				}
				else {
					printf("%05d %d ", res2[i].address, res2[i].key);
				}
			}
			printf("%05d\n", res3[0].address);
			for (int i = 0; i < res3.size(); i++) {
				if (i != res3.size() - 1) {
					printf("%05d %d %05d\n", res3[i].address, res3[i].key, res3[i + 1].address);
				}
				else {
					printf("%05d %d -1\n", res3[i].address, res3[i].key);
				}
			}
		}
	}
	else {
		if (res2.size() == 0 && res3.size() == 0) {
		 
		}
		else if (res2.size() == 0 && res3.size() != 0) {
			for (int i = 0; i < res3.size(); i++) {
				if (i != res3.size() - 1) {
					printf("%05d %d %05d\n", res3[i].address, res3[i].key, res3[i + 1].address);
				}
				else {
					printf("%05d %d -1\n", res3[i].address, res3[i].key);
				}
			}
		}
		else if (res2.size() != 0 && res3.size() == 0) {
			for (int i = 0; i < res2.size(); i++) {
				if (i != res2.size() - 1) {
					printf("%05d %d %05d\n", res2[i].address, res2[i].key, res2[i + 1].address);
				}
				else {
					printf("%05d %d -1\n", res2[i].address, res2[i].key);
				}
			}
		}
		else if (res2.size() != 0 && res3.size() != 0) {
			for (int i = 0; i < res2.size(); i++) {
				if (i != res2.size() - 1) {
					printf("%05d %d %05d\n", res2[i].address, res2[i].key, res2[i + 1].address);
				}
				else {
					printf("%05d %d ", res2[i].address, res2[i].key);
				}
			}
			printf("%05d\n", res3[0].address);
			for (int i = 0; i < res3.size(); i++) {
				if (i != res3.size() - 1) {
					printf("%05d %d %05d\n", res3[i].address, res3[i].key, res3[i + 1].address);
				}
				else {
					printf("%05d %d -1\n", res3[i].address, res3[i].key);
				}
			}
		}
	}
	return 0;
}

 

PAT甲级题目解析和知识点分类整理 个人博客:https://maxusun.github.io/ 转载请注明出处 今天整理电脑,发现了去年为了考研浙大计算机整理的PAT资料。现在考研已经尘埃落定。想到当时盲目刷题浪费了好多时间,在这里希望将整理的东西放到网上,方便后来者学习。 PAT的命题趋势 将PAT甲级中的题目从第一题刷到最后一题,可以明显感受到,PAT甲级的题目风格发生了很明显的变化。从早期的模拟型题目变成了后来以数据结构和算法为主的固定题型。如果时间紧迫的话,可以只刷后一般的题目,放弃前一半的题目,因为前一半题目的出题风格已经过时了 阅读详情

相关推荐

19年冬季第二题 PAT甲级 1165 Block Reversing (25分) 跟1133类似的题目

题目 Given a singly linked list L. Let us consider every K nodes as a block (if there are less than K nodes at the end of the list, the rest of the nodes are still considered as a block). Your job is t...

qiiingc的解题记录 1537

PAT甲级1133

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

zerohawk的博客 171

2019年9月8日秋季PAT甲级题解-2-1161-Merging Linked Lists (25 分) 双解法

Given two singly linked listsL​1​​=a​1​​→a​2​​→⋯→a​n−1​​→a​n​​andL​2​​=b​1​​→b​2​​→⋯→b​m−1​​→b​m​​. Ifn≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a li...

qiiingc的解题记录 2353

PAT 甲级 1132 1133 1134 1135 解题报告 (伪单点测试多了起来)

用时:2小时15分(最后一题花了一个多小时,bug多成山) PAT1132 剪切数 题目大意:给出一个位数为偶数的数字A,把A从中间“劈开“成两个数,请问A能否被这两个数的积整除。 思路:写一个判断位数的函数即可。 做完了发现用string读取的话似乎更好操作些。 另:一开始读错了题,以为从任意位数劈开均可,遍历了一通。费力不讨好。以后一定要读清楚题。 代码: #include <algorithm> #include <vector> #include <iostr

Modberge的博客 615

如何编写 Skill 实现自动化用例生成

Skill 本质上是一组结构化的指令和工具定义,它告诉 AI 模型在特定场景下应该遵循什么流程、调用哪些工具、输出什么格式的内容。元信息:名称、描述、版本等。指令(Instructions):定义 AI 的行为准则和任务流程。工具(Tools):AI 可以调用的外部能力,如文件读写、代码执行、API 请求等。上下文(Context):预设的输入输出格式或示例。编写一个用于自动生成测试用例的 Skill,核心在于定义清晰的指令流程和输出规范。

Cesare的博客 2690

蚂蚁区块链第20课 可信存证司法链从入门到实施

1. 摘要 杭州互联网法院和司法区块链平台的技术建设方都是蚂蚁金服区块链。那么,如何借助蚂蚁的技术能力和服务能力,快速对接上司法链,便于后续打通存证/维权的闭环流程。本文介绍蚂蚁区块链可信存证的业务及特点,费用及接入方法等,具有实战指导意义。 2. 蚂蚁区块链可信存证的介绍 蚂蚁区块链可信存证具备全链路可信,司法权威节点见证,安全隐私保护,一站式接入能力,全国首家法律认可的区块链存证平台。 2...

辉哥的技术投资路 6086

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

量化策略开发步骤系列(5)前向测试和统计意义

我们在第 4 部分,展示了我们策略的样本外测试并讨论了其结果。用于开发模型的数据是 2018 年至 2021 年的数据,测试数据是 2021 年至 2022 年的数据。但有一种方法可以更好地利用我们的数据。

码上助君的专栏 1844

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

《AgentScope-Java 深入浅出教程》第8章 工具高级特性

掌握工具组、预设参数、执行上下文等高级特性。

步子哥的博客 265

金融监管压力测试场景生成

压力测试是一种评估金融资产或机构在极端市场条件下的表现和风险承受能力的方法。它通过模拟各种不利的市场情景,测试金融机构在这些情景下的财务状况和运营能力。压力测试的作用在于帮助金融机构识别潜在风险,评估应对策略,并制定应急预案。总结压力测试场景生成系统的开发过程和实现效果,强调其在金融监管中的重要性和应用价值。随着金融市场的发展,实时压力测试将越来越重要。未来,压力测试需要更加注重实时性和动态性,及时反映市场的变化。本文详细介绍了金融监管压力测试的重要性、核心概念、算法原理、系统架构以及实战案例。

AI天才研究院 1208

PAT甲级 1133 - Splitting A Linked List

这里可以分成三类,用三个vector保存。第一类是小于0的;第二类是大于0但是小于k的;第三类是大于k的;但我是直接使用sort排序里面的cmp重写做的(注意使用stable_sort就行了)。 #include&lt;bits/stdc++.h&gt; using namespace std; const int maxn=100000+10; int startAddress,n,k; st...

Mr0cheng的专栏 344

RT-DETR改进策略【Conv和Transformer】| HiLo注意力机制 通过分离处理图像的高频和低频信息,高效处理图像特征

本文记录的是利用改进检测模型,针对目标检测中面临的多尺度特征融合效率与长距离依赖建模难题,HiLo注意力模块的引入旨在通过频率解耦策略优化高分辨率特征处理,将高频细节(如目标边缘)与低频语义(如场景结构)分离建模,提升目标检测精度。Fast Vision Transformers with HiLo AttentionHiLo注意力模块的提出源于对传统自注意力机制局限性的反思。传统多头自注意力(MSA)在处理高分辨率图像时存在以下问题:HiLo将注意力模块分为高频(Hi-Fi)和低频(Lo-Fi)两个分支,

Limiiiing的博客 817

PAT甲级按题型分类

PAT甲级按题型分类 1. 水题篇 2. 数据结构篇 2.1 线性表 结构框架 顺序结构:顺序表 链式结构:单链表、双链表、循环链表(指针);静态链表(借助数组) 2.2 栈&队 结构框架 栈:顺序栈、链栈、共享栈 队列:循环队列、链式队列、双端队列 数组(推广):一维数组、对维数组(压缩、稀疏矩阵) 2.3 串 结构框架 基本功概念:主串、子串、串长 存储结构:定长顺序存储、堆分配存储、块链存储 模式匹配算法:暴力匹配、KMP算法(部分匹配值表、next数组、next函数的推理)、kmp

TypicalSpider的博客 3939

微搭低代码实现用户登录及注册功能

在小程序开发中,我们可以拿到微信用户的openid,openid可以作为用户的唯一标识,在查询数据的时候可以进行数据过滤实现查询自己提交的数据。那微搭中是否也有openid这个概念,可以获取用户自己提交的数据呢? 答案是肯定的,那要怎么去做呢?思路是先创建一个数据源方法,在数据源中返回openid,然后低代码中可以调用数据源的方法并且赋值给全局变量,这样在后续的业务中从全局变量就可以获取openid了,方便做数据权限的控制。 为了实现这个目的,我们从创建数据源开始。 创建数据源 我们先创建一个用户管理的数据

低代码布道师的博客 2997

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

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

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

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

NTscan扫描工具

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

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

PAT甲级解题目录

PAT甲级解题目录 ID Title C/C++题解 1001 A+B Format (20) 查看题解 1061 Dating (20) 查看题解 1062 Talent and Virtue (25) 查看题解 1063 Set Similarity (25) 查看题解 1064 Com...

萧易桥的博客 646

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

刷题

阿正的梦工坊 402

PAT刷题记录-甲级

前言 记录PAT刷题笔记和代码。算法笔记中例题的记录已经放在《算法刷题笔记》文章中了。以下是PAT题库中算法笔记中未出现的题目,这里均为PAT甲级题目。 甲级 A1001

Maxi_0902的博客 1422

PAT甲级题目分类【持续更新】

准备开一个PAT甲级的题解专栏,将题目按照分类罗列在此,方便找到对应的题目,有针对性行的进行刷题

郭同学如是说 488

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

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

Newin2020的博客 483

PAT甲级118-155题解析笔记索引-扩充《算法笔记》(解析+思路+AC代码)

前言 PAT索引 题目 类型 1001 A+B Format

九筒的博客 447

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甲级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甲级1097解题报告
下一篇: PAT甲级1128解题报告
Tate_Brown
博客等级 码龄9年 39粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值