A1052 Linked List Sorting 链表的题坑太深

别再手动转格式了!用Java+LibreOffice命令行实现Word批量转PDF(附Docker部署避坑指南) 本文详细介绍了如何利用Java和LibreOffice命令行实现企业级Word批量转PDF的自动化解决方案,包括多线程优化、Docker化部署及常见问题排查。通过代码示例和实战经验,帮助开发者高效处理文档转换需求,提升工作效率并避免常见陷阱。 阅读详情

【题目描述】
1052 Linked List Sorting
A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, you are supposed to sort the structures according to their key values in increasing order.
【Input Specification】
Each input file contains one test case. For each case, the first line contains a positive N (<10​5​​) and an address of the head node, where N is the total number of nodes in memory and the address of a node is a 5-digit positive integer. NULL is represented by −1.
Then N lines follow, each describes a node in the format:
Address Key Next
where Address is the address of the node in memory, Key is an integer in [−10​5​​,10​5​​], and Next is the address of the next node. It is guaranteed that all the keys are distinct and there is no cycle in the linked list starting from the head node.
【Output Specification】
For each test case, the output format is the same as that of the input, where N is the total number of nodes in the list and all the nodes must be sorted order.
【Sample Input】
5 00001
11111 100 -1
00001 0 22222
33333 100000 11111
12345 -1 33333
22222 1000 12345
【Sample Output】
5 12345
12345 -1 00001
00001 0 11111
11111 100 22222
22222 1000 33333
33333 100000 -1
在这里插入图片描述
【坑】
链表的题都不难,但是不了解的人很难做全对,几乎在题库中能找到的甲级乙级的关于链表的题,都涉及到一个问题:无效节点,如果想不到这个的话很难AC,我就是这样,哭唧唧!(下面的代码是可以AC的代码)
【code】

#include<iostream>
#include<algorithm>
using namespace std;
struct node{
    int address,data,next,flag=0;
};
typedef struct node NODE;
NODE jd[100005],rs[100005];
bool cmp(NODE x,NODE y){
    return x.data<y.data;
}
int hashtable[100005]={0};
int main(){
    int N,i,start,cnt=0;
    scanf("%d%d",&N,&start);
    for(i=0;i<N;i++){
        scanf("%d%d%d",&jd[i].address,&jd[i].data,&jd[i].next);
        hashtable[jd[i].address]=i;
    }
    for(i=0;i<N&&start!=-1;i++){
        jd[hashtable[start]].flag=1;
        rs[i]=jd[hashtable[start]];
        start=jd[hashtable[start]].next;
        cnt++;
    }
    sort(rs,rs+cnt,cmp);
    if(cnt==0){
        printf("0 -1");
        return 0;
    }
    else{
        printf("%d %05d\n",cnt,rs[0].address);
        for(i=0;i<cnt-1;i++)
            printf("%05d %d %05d\n",rs[i].address,rs[i].data,rs[i+1].address);
        printf("%05d %d -1\n",rs[i].address,rs[i].data);
    }
    return 0;
}
Codex智能体从零搭建:环境配置、代码管理与MCP扩展实战 AI智能体(Agent)作为连接大语言模型与实际应用的关键技术,通过感知、决策与执行框架,将AI能力融入具体工作流。其核心原理在于利用提示工程、上下文管理与工具调用,将自然语言指令转化为可执行操作。在软件开发领域,AI智能体能够显著提升代码生成、项目管理和自动化任务的效率。通过Model Context Protocol(MCP)等标准化协议,智能体可以安全、结构化地集成外部工具与服务,实现能力扩展。本文聚焦于Codex这一AI驱动的代码助手平台,详细解析其环境配置、代码索引、记忆系统等核心模块,并深入探讨 阅读详情

相关推荐

Oracle数据库的内存管理优化技巧

Oracle数据库作为企业级数据库管理系统,广泛应用于各种业务场景。内存管理是Oracle数据库性能优化的关键环节,合理的内存管理可以显著提高数据库的响应速度和吞吐量。本文的目的是深入探讨Oracle数据库内存管理的优化技巧,涵盖了系统全局区(SGA)和程序全局区(PGA)的管理、内存分配算法、内存参数调整等方面。通过详细的讲解和实际案例分析,帮助读者掌握优化Oracle数据库内存使用的方法,提高数据库的性能和稳定性。

2502_91592937的博客 998

1052 Linked List Sorting

1052 Linked List Sorting 题目大意 将读入的结点根据是否有效(是否在链表上)和key值的大小排序后,输出所有有效结点(是否在链表上)的address key 和 当前结点的下一个结点的address。(排序后结点的顺序发生了变化,当前结点的next不再是下一个结点的adress) 核心思路 思路借鉴于柳神,链接如下: https://blog.youkuaiyun.com/liuchuo/article/details/52144537 建立结构体数组,按照首地址开始的顺序(直到-1)遍历一

Baifeili的博客 174

避坑指南:Zephyr RTOS与nRF Connect SDK环境搭建常见错误及解决方案

本文详细解析了Zephyr RTOS与nRF Connect SDK环境搭建过程中的常见错误及解决方案,涵盖网络问题、代理设置、SEGGER Embedded Studio配置、分支切换等关键环节。针对开发者实际遇到的痛点问题,提供了一系列实用技巧和深度排错方法,帮助高效完成NCS开发环境部署。

weixin_28685287的博客 172

1052 Linked List Sorting(25分)

有5个结点,输入第一个结点的地址,下面5行分别是结点的地址,数据域,next域,给这五个结点按数据域的大小从小到大排列,重新建立链表,输出有多少个有效的结点,和第一个结点的地址,然后输出各个结点的地址,数据域和next域。因为可能有不在链表中的结点,所以要先建立链表,然后排序输出。:可能是因为没建立链表,样例中还有链表外的数据。

a131529的博客 541

VH6501干扰仪的使用

触发模式方法备注External Trigger(外部触发)使用VH6501的I/O口作为触发源Frame Trigger(报文触发)设定被干扰报文的触发位置,并发送干扰位序列/报文software Trigger(软件触发)配置好干扰序列后直接发送Error Frame Trigger(错误帧触发)基于错误帧标识位为触发条件触发干扰Direction Trigger(发送方向触发)根据TX/RX发送/接收方作为触发条件Inverted Trigger(反向触发)

帮助100万人颠覆负面潜意识,实现人生蜕变,培养1万名潜意识开发导师 9057

YALMIP介绍及怎么在Matlab中加YALMIP、SDPT3

目录YALMIP简介怎么在Matlab中加YALMIP?1. 创建决策变量:2. 添加约束:3. 参数配置4. 求解怎么在MatlabR2019a中加YALMIP?1.下载工具包2.放置工具包3.添加路径4.测试安装结果怎么在MatlabR2019a中加SDPT3? YALMIP简介 怎么在Matlab中加YALMIP? yalmip是一位“集大成者”,它不仅自己包含基本的线性规划求解算法,比如linprog(线性规划)、bintprog(二值线性规划)、bnb(分支界定算法)等,他还提供了对cpl

m0_51431440的博客 2万+

*PAT_甲级_1052 Linked List Sorting (25分) (C++)【链表排序】

1,题目描述 2,思路 (不明白为什么要给出头节点。。。) 3,代码 #include<iostream> #include<vector> #include<string.h> #include<algorithm> using namespace std; struct node{ int add, ke...

&再见萤火虫&的博客 291

433M无线遥控器EV1527协议解码实战:从逻辑分析到代码优化

本文详细解析了433M无线遥控器EV1527协议的实战解码过程。从使用逻辑分析仪抓取波形、理解同步头与数据位编码原理开始,逐步深入代码实现。文章重点对比了原始定时器轮询法的痛点,并提出了基于“边沿捕获+时间戳”的优化方案,构建了高效、可移植且具备抗干扰能力的解码引擎,最后分享了跨平台移植的核心技巧。

weixin_29168813的博客 928

【PAT】1052. Linked List Sorting (链表)及测试点问题

【PAT】1052. Linked List Sorting (链表)及测试点问题 题目原文: 1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to

weixin_43827530的博客 731

复合材料RVE建模与力学性能分析实战指南

代表体积元(RVE)建模是复合材料多尺度分析的核心技术,通过建立微观结构与宏观性能的定量关联,可准确预测材料力学行为。本文基于ABAQUS平台,详细解析三材料(纤维/基体/界面相)RVE建模全流程,包括参数化几何建模、周期性网格划分策略、材料属性定义技巧等关键技术环节。针对碳纤维增强环氧树脂等典型复合材料,提供网格控制参数建议和材料参数参考表,并重点说明周期性边界条件的实现方法与验证标准。通过Python脚本自动化处理和优化分析流程,可显著提升计算效率,为复合材料设计提供可靠仿真依据。

weixin_34062469的博客 549

UE5 Niagara基础知识讲解

在UE5版本中,Niagara粒子系统引入了许多可添加的模块,分别用于控制发射器的生成和更新、粒子的生成和更新以及渲染效果。本文采用虚幻5.2.1版本,以图文方式对Niagara基础知识进行讲解。

一碗清深的博客 2473

1052 Linked List Sorting (巨坑题)

题意:以address,val,next_address的形式给定一个链表,同时给定头节点的address,求将该链表排序后的形式。坑点二:没想到吧,给定的链表还可能为空!这种情况下,我们只需要输出0与头结点就行了。坑点一:有的结点不在该链表上,需要遍历一遍链表排除掉。(可以用哈希表存储链表)pat拿分简单,但是拿要高分确实难。

qq_63128300的博客 896

第十五章数据管理成熟度评估【6’】(DAMA-CDGA 2022年以后历年模拟题真题汇总,基本包含所有考点。)

第十五章数据管理成熟度评估【6’】(DAMA-CDGA 2022年以后历年模拟题真题汇总,基本包含所有考点。)

JasonH2021的博客 406

「1052」Linked List Sorting

A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integerkeyand aNextpointer to the next structure....

weixin_52435933的博客 172

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

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

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

(PAT甲级) 1052 Linked List Sorting(静态链表)

3.对遍历到的点做处理,并计数(因为题目会给出一些不在链表上的点)int address;//本身地址属性不会变。struct Node{//1.定义静态链表。Node 是 结构体类型 的名称。node 作为数组变量名。2. 对链表进行初始化。

zeng_han_cheng的博客 407

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

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

PAT|1052 Linked List Sorting(链表、排序、结构体)

题目大意 链表由一系列结构组成,这些结构在内存中不一定相邻。我们假设每个结构都包含一个整数键和一个指向下一个结构的Next指针。现在给出了一个链表,您应该按照其键值按升序对结构进行排序。 做题分析 本来以为只要控制好节点自己的地址和值即可,因此直接使用了map排序解决的问题。最后提交才发现部分用例无法通过。看了柳神的题解才知道有的节点根本不在链表之中。 给大家看看错误代码,引以为戒。 #include<bits/stdc++.h> using namespace std; int n

qq_43528044的博客 222

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

【1052】Linked List Sorting (链表)

#include <cstdio> #include <algorithm> #include <stdlib.h> using namespace std; const int maxn=100005; struct Node{ int address,data,next; bool flag; //结点是否在链表上 }node[maxn]; bool...

发现问题,并解决问题,批判性思维 667

1052. Linked List Sorting

A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now give...

futangxiang4793的博客 272

leetcode 237. Delete Node in a Linked List(链表中删除节点)

leetcode 237

蓝羽飞鸟的博客 435

【PAT(甲级)】1052 Linked List Sorting(测试点3,4)

给出链表,要求我们按照key从小到大的顺序重新排列链表。坑的地方在于,他没说如果给出的链表头是-1或者压根就不存在下面的数据里面的时候要输出“0 -1”(测试点4)。 我们定义两个结构,一个存储数据,一个存储链表的数据。数组的address就是数组的下标,这样就方便找到next对应的数组,并且当重新排列后,就可以直接输出address来输出了。...

weixin_55202895的博客 517

1052 Linked List Sorting (25 分)(元旦元旦元旦!!!!!!)

A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integerkeyand aNextpointer to the next structure. Now giv...

qq_43813697的博客 205

1052 Linked List Sorting (25 分)测试点4

1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, you are

weixin_45050148的博客 268

【PAT】1052 Linked List Sorting 测试点分析

题目 A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, you are supposed to sort the structu

目标:NLP算法工程师 814
上一篇: 如何让QT5支持C++11新特性
下一篇: 建树->先序-中序-后序-层次遍历
菜菜2022
博客等级 码龄9年 67粉丝 1033原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值