PAT甲级1097解题报告

pta 2019乙级春赛 矩阵行平移 矩阵行平移 给定一个 n×n 的整数矩阵。对任一给定的正整数 k<n,我们将矩阵的奇数行的元素整体向右依次平移 1、……、k、1、……、k、…… 个位置,平移空出的位置用整数 x 补。你需要计算出结果矩阵的每一列元素的和。 输入格式: 输入第一行给出 3 个正整数:n(<100)、k(<n)、x(<100),分别如题面所述。 接下来 n 行,每行给出 n 个不超过 100 ... 阅读详情

1097 Deduplication on a Linked List (25 point(s))

Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or absolute value of its key equals K will be kept. At the mean time, all the removed nodes must be kept in a separate list. For example, given L being 21→-15→-15→-7→15, you must output 21→-15→-7, and the removed list -15→15.

Input Specification:

Each input file contains one test case. For each case, the first line contains the address of the first node, and a positive N (≤10​5​​) which is the total number of nodes. 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 Key Next

where Address is the position of the node, Key is an integer of which absolute value is no more than 10​4​​, and Next is the position of the next node.

Output Specification:

For each case, output the resulting linked list first, then the removed list. Each node occupies a line, and is printed in the same format as in the input.

Sample Input:

00100 5
99999 -7 87654
23854 -15 00000
87654 15 -1
00000 -15 99999
00100 21 23854

Sample Output:

00100 21 23854
23854 -15 99999
99999 -7 -1
00000 -15 87654
87654 15 -1

题目大意:去除链表的重复绝对值元素然后输出去除后的链表和删除后的元素。

解题思路:简单模拟。

#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;
map<int, int> a;//记录次数
map<int, int> b;//记录add-key
map<int, int> c;//记录add-next
int main()
{
	int start, n;
	scanf("%d %d", &start, &n);
	if (n == 1) {
		int hh, gg, kk;
		scanf("%d %d %d", &hh, &gg, &kk);
		printf("%05d %d -1\n", hh, gg);
	}
	else {
		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;
			/*if (a[abs(cur.key)] == 0) {
				a[abs(cur.key)] += 1;
				res1.push_back(cur);
			}
			else {
				res2.push_back(cur);
			}*/
		}
		while (start != -1) {
			node cur;
			cur.address = start;
			cur.key = b[start];
			cur.next = c[start];
			if (a[abs(cur.key)] == 0) {
				a[abs(cur.key)] += 1;
				res1.push_back(cur);
			}
			else {
				res2.push_back(cur);
			}
			start = cur.next;
		}

		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 -1\n", res1[i].address, res1[i].key);
		}
		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);
		}
	}
	return 0;
}

 

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

相关推荐

KUKA机器人自动回原点程序

创建两个全局变量分别用于储存机器人的笛卡尔姿态与关节角姿态。打开System文件夹中的config文件创建全局变量的点位。在USER GROBALS用户自定义变量Userdefined variables下创建一个E6POS类型的点位,一个E6AXIS类型的点位。

A567852的博客 5210

1097 矩阵行平移 – PAT乙级真题

给定一个n×n的整数矩阵。对任一给定的正整数k

柳婼 の blog 1236

时钟MUX电路结构的时序约束方法分析

一、最简单的设置 对于时钟MUX而言,其output_pin上的时钟在任一时刻一定唯一。可以使用如下命令: set_clock_exclusivity -output output_pin [-type mux | user_defined] ...

Jackiezhang1993的博客 1万+

PAT甲级真题1097 链表重复数据删除(简单解法)

给定一个单链表 LL,链表上的每个节点都存有一个键值,你应该删掉其中拥有重复键值绝对值的节点。 也就是说,对于每个值 KK,只保留键值或键值绝对值为 KK 的第一个节点。 同时,被删掉的节点也应保存在一个单独的链表中。 例如,给定 LL 为 21→-15→-15→-7→15,则删除重复数据后的链表为 21→-15→-7,已删除链表为 -15→15。 输入格式 第一行首先包含头节点地址,然后包含节点总数 NN。 节点地址用一个 55 位非负整数表示(可能有前导 00),NULL 用 −1−1 表示。 接下来

qq_43738331的博客 392

电网渗透之终端安全

        电力系统安全不仅关系到电网的稳定运行,也关系到国家能源安全和国计民生,甚至关系到国家的安全和利益,电力系统由于结构复杂多样、分布广泛、重要性高,一旦系统瘫痪影响巨大,因此,极容易成为敌对势力攻击的首选目标。随着信息安全暴露面迅速增加,将给公司网络安全防线带来严峻挑战。       监控、保障这些电力系统安全运行变的尤为重要。内部安全防护产品有防火墙、纵向加密、反向隔离设备等...

guapi007008的博客 2721

华为OD机考2025C卷 - 精准核酸检测(Java & Python& JS & C++ & C语言)

华为OD机考2025C卷 - 精准核酸检测,提供在线OJ Java & Python& JS & C++ & C

算法大师! 2881

PAT甲级1097 Deduplication on a Linked List (25分) 解析测试点1 和测试点 2 , list 表示链表 删除元素 逆遍历

1097 Deduplication on a Linked List (25分) Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, o...

qq_32691667的博客 1139

从技术债红线到系统治理:透视 SAP Clean Core 中的 Level D

SAP推出的Clean Core分级体系将扩展风险划分为A到D四个等级,其中Level D代表最高风险类别,涉及直接修改标准代码、隐式增强、使用noAPI对象等不被推荐的做法。这些做法虽然短期见效快,但会带来升级冲突、数据完整性风险等长期问题。SAP强调治理重点不是完全消除经典ABAP,而是优先清理Level D对象,逐步向稳定接口迁移。典型案例显示,依赖内部细节的扩展往往在系统升级或云迁移时集中暴露出问题。企业应通过工具链持续监控Level D占比,将其纳入技术债管理范畴。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1063

PAT甲级1097

1097. Deduplication on a Linked List (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a singly linked list

湛蓝的天空 660

即插即用系列(代码实践) | CVPR 2025 FDConv:频域动态卷积,打破密集预测任务的参数效率瓶颈

本文提取自 CVPR 2025 的最新底层算子革新论文《Frequency Dynamic Convolution for Dense Image Prediction》。近年来,动态卷积(Dynamic Convolution)通过融合多个并行卷积核极大地提升了模型性能,但研究表明:这些并行卷积核在频域上的响应高度相似,导致了极其严重的参数浪费,且缺乏对不同频率特征的自适应能力。本文复现了该网络的核心架构——FDConv(频率动态卷积)。该方案创造性地在傅里叶域(Fourier Domain)中学习固定参

分享顶会顶刊论文即插即用模块 111

安川机器人外部轴添加

本文详细介绍了如何在安川机器人本体上添加第7轴以及如何设置动作,本文以添加点焊枪为例进行讲解。

haier123888的博客 7889

PAT甲级 1097

PAT甲级 1097题目解析代码 题目 Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of...

qq_37208650的博客 270

从零开始做对容量规划:一文讲透 SAP Greenfield sizing 与 Quick Sizer 落地方法

摘要 SAP项目早期硬件规划面临业务细节缺失的挑战,Greenfield sizing方法通过Quick Sizer工具将业务需求转化为硬件资源需求。该方法聚焦主要负载驱动因素而非精确预测,采用标准化问卷形式输入并发用户数、业务处理量等参数,输出内存、CPU等资源需求。关键步骤包括选择正确的Quick Sizer版本、创建sizing项目、参考SAP基准测试和认证目录校准结果,最终将需求交由硬件厂商落地。该方法特别适用于缺乏历史数据的新系统部署,帮助在不确定性中建立可控的容量规划模型,避免资源浪费或性能不足

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 211

PAT甲级部分python解题记录

用Python写PAT甲级,答案都在这了。每一道题都有原题、题目大意以及代码实现,大部分的题目都有详细的逻辑分析。欢迎大家一起来讨论!

贰拾壹 4479

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

蓝牙模块HM-10手册

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

PAT甲级按题型分类

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

TypicalSpider的博客 3939

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

PA甲级 A1097

PAT甲级 A1097 题目详情 1097 Deduplication on a Linked List (25分) Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value o

weixin_44065549的博客 176

PAT甲级题目索引

PAT甲级 1001 PAT甲级 1002 PAT甲级 1003 PAT甲级 1004 PAT甲级 1005 PAT甲级 1006 PAT甲级 1007 PAT甲级 1008 PAT甲级 1009 PAT甲级 1010 PAT甲级 1011 PAT甲级 1012 PAT甲级 1013 PAT甲级 1014 PAT甲级 1015 PAT甲级 1017 PAT甲级 1018 PAT甲级 1019 PA...

化身孤岛的鲸o的博客 983

PAT甲级总结文

PAT甲级总结文(持续更新) 1089 Insert or Merge (25 分) 实现插入排序和归并排序

不屈不挠的拉普 989

PAT甲级——1097 Deduplication on a Linked List (链表)

1097Deduplication on a Linked List(25分) Given a singly linked listLwith integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each valueK,...

小熊猫的博客 356

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

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

郭同学如是说 488

PAT甲级1097 Deduplication on a Linked List:[C++题解]遍历链表、两个vector

刷题

阿正的梦工坊 454

【PAT甲级 - C++题解】1097 Deduplication on a Linked List

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

Newin2020的博客 714

2021-03-02PAT甲级1097 Deduplication on a Linked List (25 分)思路

思路:应用静态链表的知识。

优快云_Ysu的博客 243

【转载】【pat】PAT甲级真题目录(按题型整理)

最短路径 1003. Emergency (25)-PAT甲级真题(Dijkstra算法) 1018. Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) 1030. Travel Plan (30)-PAT甲级真题(Dijkstra + DFS,输出路径,边权) 1087. All Roads Lead to Rome (30)-PAT甲级真题...

weixin_45855916的博客 468

PAT 甲级 A1097

1097 Deduplication on a Linked List (25分) 题目描述 Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value...

灯灯登登的博客 273
上一篇: PAT甲级1141解题报告
下一篇: PAT甲级1133解题报告
Tate_Brown
博客等级 码龄9年 39粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值