【PTA-A】1097 Deduplication on a Linked List (25 分)(链表)

【液晶专题】从外挂到In-Cell/ On-Cell/ OGS再也不会傻傻分不清楚了 触控技术经历了从外挂式到内嵌式的革新,主要方案包括外挂式(Out-Cell)、OGS、On-Cell和In-Cell。 阅读详情

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>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 100010;
struct Node {
	int ad, key, next;
	int order;
}no[MAXN];
int a[MAXN];
bool cmp(Node a, Node b) {
	return a.order < b.order;
 }
int main() {
	int start, n;
	cin >> start >> n;
	int temp;
	memset(a, 0, sizeof(a));
	for (int i = 0; i < MAXN; i++)
		no[i].order = MAXN*2;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		scanf("%d %d", &no[temp].key, &no[temp].next);
		no[temp].ad = temp;
	}
	int p = start,cho=0,del=0;
	while (p != -1) {
		temp = abs(no[p].key);
		if (a[temp] == 0) {
			a[temp] = 1;
			no[p].order = cho++;
		}
		else {
			no[p].order = MAXN+del++;
		}
		p = no[p].next;
	}
	int count = cho + del;
	sort(no, no + MAXN, cmp);
	for (int i = 0; i < count; i++) {
		if (i != cho - 1 && i != count - 1) {
			printf("%05d %d %05d\n", no[i].ad, no[i].key, no[i+1].ad);
		}
		else {
			printf("%05d %d -1\n", no[i].ad, no[i].key);
		}
	}
	return 0;
}

 

如何用SoulChat2.0快速克隆你的心理咨询师?手把手教你搭建AI数字孪生体 本文详细介绍了如何利用SoulChat2.0框架快速构建心理咨询师的AI数字孪生体。通过其核心PsyDT技术,仅需少量真实案例即可合成风格数据并微调大模型,从而低成本地创建能高度模仿特定咨询师语言风格和专业技术的AI分身,适用于预约访谈、心理教育等辅助场景,实现高效的人机协作。 阅读详情

相关推荐

Unity2019编译器下使用Ump无错误,打包exe不播放 或 将exe文件在其他电脑下运行不播放

一、unity编译器下使用UMP可以播放视频,打包后查看debug 出现错误 UnloadTime: 1.070900 ms Fallback handler could not load library F:/PCTest/AccessControlSysteam/jfmx_Data/Mono/libdl Fallback handler could not load library F:/PCTest/AccessControlSysteam/jfmx_Data/Mono/libdl.dll Fa.

qq_42345116的博客 4699

PTA甲级 1097 Deduplication on a Linked List (C++)

Given a singly linked list LLL with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value KKK, only the first node of which the value or absolute value of its key equals KKK will be kept. At

Misdirection 226

RK3588极速成功部署YOLO26完整全链条:从pt导出、ONNX转换到rknn-toolkit-lite2落地与CMA内存优化

帮助你顺利完成pt模型到瑞星微3588上rknn模型的高效部署

昆兰.沃斯 的博客 532

1097 Deduplication on a Linked List (25分)

题目 Given a singly linked list LLL with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value KKK, only the first node of which the val...

小白的博客 230

【数据结构】汉诺塔问题(丰富图解)

经典汉诺塔问题,丰富图解,助你理解。

℉f的博客 4105

LPDDR6 技术标准详解(JESD209-6)

是继 LPDDR5/5X 之后的新一代低功耗 DRAM 标准,专为满足移动终端、AI、边缘计算等高带宽、低功耗场景而设计。该标准通过全新架构、动态功耗控制机制和增强型数据完整性机制,实现性能、能效与可靠性的全面升级。LPDDR6 并非仅是速度升级,更是内存架构设计思路的演进,围绕“低功耗 + 高带宽 + 强安全”的三维目标,构建下一代 SoC 平台关键基础。✅ 高带宽:支持 32B/64B 动态突发✅ 低功耗:动态电压、通道切换✅ 高可靠性:ECC + 自测试 + 安全区。

weixin_43199439的博客 2567

1097 Deduplication on a Linked List

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 a...

无名小白的博客 194

教你写出高质量SQL(实践必备)

1、查询SQL尽量不要使用select * ,而是select具体字段。 //反例子 select * from sys_user; //正例子 select id,name from sys_user; 理由: 只取需要的字段,节省资源、减少网络开销;select * 进行查询时,很可能就不会使用到覆盖索引,就会造成回表查询; 覆盖索引:只需要在一棵索引树上就能获取SQL所需的所有列数据,无需回表,速度更快。 例如: 回表查询:先通过普通索引的值定位聚簇索引值,再通过聚簇索引的值定位行记..

ANGEL CITY 9996

PAT A1097 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 or a...

weixin_44620697的博客 221

【华为OD机试真题】7、字符串筛选排序 | 机试真题+思路参考+代码解析(C++、Java、Py)

题目描述 >输入一个由N个大小写字母组成的字符串 按照ASCII码值从小到大进行排序 查找字符串中第K个最小ASCII码值的字母(k>=1) 输出该字母所在字符串中的位置索引(字符串的第一个位置索引为0) k如果大于字符串长度则输出最大ASCII码值的字母所在字符串的位置索引 如果有重复字母则输出字母的最小位置索引

KJ.JK 2265

推荐系统[九]项目技术细节讲解z2:搜索Query理解[Term Weight、Query 改写、同义词扩写]和语义召回技术

在 pooling 方法上,我们也尝试过不同层 pooling,或者在多层上增加 attention 聚合 BERT 多层结果,效果和最后一层所有 token 做 average pooling 相当。损失函数方面,在排序阶段使用pairwise比 pointwise 损失函数的效果会更好。

丨汀、的博客 1108

1097 Deduplication on a Linked List (Map构建链表)

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 m

qq_43813373的博客 214

手把手教你玩转服务器芯片架构​专栏--​​3.5 实战案例:用SystemC搭建一个多核服务器芯片的NoC模型(含流量分配与延迟仿真)​

通过SystemC搭建多核NoC模型,可深入验证流量分配策略与延迟特性。实际工程中需结合FPGA原型验证(如Xilinx Alveo)进行时序收敛分析,并通过参数化设计适配不同服务器芯片需求。

MHD0815的博客 3042

1097 Deduplication on a Linked List (25分)[静态链表][hash散列]

By Jalan 文章目录**By Jalan**知识工具需求数学数据结构和算法语言题干输入条件例1输出条件例1题解第一次思路预期时间复杂度编写用时代码CPP运行用时结尾 知识工具需求 数学 数据结构和算法 静态链表 hash散列 语言 一般产生段错误的原因就是数组下标访问越界了,这种越界特别可能出现在 单独访问数组内特定的某个位置(需要验证位置是否存在) 需要对数组的开头,结尾做特殊处理(需要验证是否有开头结尾,部分情况下还要验证他们是否一致等) 题干 给一个单链表L,key是整数,对于每个k

JalanChao的博客 568

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

PTA甲级 1097 Deduplication on a Linked List (25分)-链表处理

title: PTA 1056 Mice and Rice (25分) date: 2020-10-02 15:43:59 tags: 链表 categories: [刷题,PAT] 文章目录题目原文Input Specification:Output Specification:Sample Input:Sample Output:生词如下:题目大意:思路如下:测试点二报错的解决方法我的代码如下:柳神的分析柳神的代码: 强烈推荐,刷PTA的朋友都认识一下柳神–PTA解法大佬 本文由参考于柳神博客写.

Huangpengyu123的博客 322

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

PTA甲级考试真题练习97——1097 Deduplication on a Linked List

题目 思路 使用set集合存储之前出现过的key,如果在有不同的就存入另一个vector,所以使用两个vector存储两个链表的当前地址和结点,最后输出即可,注意vector为空的时候不输出 代码 #include <iostream> #include <vector> #include<unordered_set> using namespace std;...

醉等佳人归 178

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

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

PAT--1097 Deduplication on a Linked List

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805369774129152 题目大意 给你一个链表的头结点,在这个链表中,重新输出链表使得不存在绝对值相等的结点(如果有相等的,只输出按链表顺序的第一个),那些被抛弃的点也组成新的链表输出。 分析 只说一下坑点吧:给的n个数不一定全用上,例如,给你10个...

黄油^小饼干的博客 204

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

还是利用静态链表的板子,因为最后要输出不被删和被删的点,所以将结构体中的order初始化为MAX,这样将不被删点的order=count++,删去的点的order=MAX+remove++,无效点的order=2MAX,这样在之后的排序中就能将链表按用被删的点 删的点 无效点 排序,并且进行输出。输出的时候注意特判是否为最后一个点。

zeng_han_cheng的博客 358

PAT A1097 Deduplication on a Linked List (25分)

#include <cstdio> #include <map> #include <cstdlib> using namespace std; struct Node{ int address, data, next; int flag; }node[100010]; map<int,int> m; int main(){ int h, n; scanf("%d %d", &h, &n); int ad; for(i.

weixin_45964844的博客 168

【PAT】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...

tjj1998的博客 209

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 or a

啦啦啦的博客 262

PAT_A1097#Deduplication on a Linked List

Source: PAT A1097Deduplication on a Linked List(25分) Description: Given a singly linked listLwith integer keys, you are supposed to remove the nodes with duplicated absolute values ...

weixin_30952103的博客 169

【一天一道】Given a linked list, return the node where the cycle begins

Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up: Can you solve it without using extra space? 解题思路:快慢指针,从起点走,快指针步长为2,慢指针步长为1,假设有环,相遇时,快指针走了...

wwb_nuaa的博客 431

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 or a...

ysq96的博客 268
上一篇: 【PTA-A】1052 Linked List Sorting (25 分)(链表)
下一篇: 【PTA-A】1103 Integer Factorization (30 分)(DFS深搜)
Netceor
博客等级 码龄9年 1046粉丝 306原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值