题意:

输入一个正整数N(<=100000),和一个链表的头结点地址。接着输入N行,每行包括一个结点的地址,结点存放的值(-1e5~1e5),指向下一个结点的地址。地址由五位包含前导零的正整数组成。以头结点地址开始的这条链表以值排序后得到的链表的长度和头结点,接着以升序按行输出每个结点的地址和值以及指向下一个结点的地址。

trick:

题干说的postive N可是数据点4出现了N==0的数据,有些不解如果N==0应该包含的话不应该用nonnegative N吗。。。

数据点1包含有些结点并非在头结点所在的这条链表上。(题干说给一条联通的链表,实际可能有些点并不在该链表上)

通过一些题目可见,有些trick不会明显的在题干中给出,题干只保证一些一定不会发生的情况,还有一些边界条件以及可能出现的问题需要自行多加考虑。。。。。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
pair<int,int>pr[];
pair<int,int>ans[];
int main(){
int n;
int add;
scanf("%d%d",&n,&add);
for(int i=;i<=n;++i){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
pr[x]={y,z};
}
int cnt=;
while(){
if(pr[add].second){
ans[++cnt].first=pr[add].first;
ans[cnt].second=add;
add=pr[add].second;
}
else
break;
}
if(!cnt)
printf("0 -1");
else{
sort(ans+,ans++cnt);
printf("%d %05d\n",cnt,ans[].second);
for(int i=;i<=cnt;++i){
printf("%05d %d ",ans[i].second,ans[i].first);
if(i!=cnt)
printf("%05d\n",ans[i+].second);
else
printf("-1");
}
}
return ;
}

【PAT甲级】1052 Linked List Sorting (25 分)的更多相关文章

  1. PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)

    1052 Linked List Sorting (25 分)   A linked list consists of a series of structures, which are not ne ...

  2. 【PAT】1052 Linked List Sorting (25)(25 分)

    1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...

  3. PAT甲级1052 Linked List Sorting

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805425780670464 题意: 给定一些内存中的节点的地址,值 ...

  4. PAT Advanced 1052 Linked List Sorting (25) [链表]

    题目 A linked list consists of a series of structures, which are not necessarily adjacent in memory. W ...

  5. 1052 Linked List Sorting (25分)

    题目 1. 思路 使用map存放所有的地址对 使用起始地址遍历map,结果存放在vector中 排序vector 输出vector 2. 注意点 开始的时候起始地址为-1 可能有些节点没有用到,注意排 ...

  6. 【PAT甲级】1028 List Sorting (25 分)

    题意: 输入一个正整数N(<=100000)和C(C属于{1,2,3}),接下来输入N行,每行包括学生的六位学号(习惯用string输入,因为可能有前导零),名字和成绩(正整数).输出排序后的信 ...

  7. PAT 解题报告 1052. Linked List Sorting (25)

    1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...

  8. Pat 1052 Linked List Sorting (25)

    1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  9. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

随机推荐

  1. 启动docker报Failed to start Docker Application Container Engine.解决

    [root@docker ~]# systemctl status docker.service● docker.service - Docker Application Container Engi ...

  2. active Directory域服务安装配置

    1.在Windows功能启用 2.安装一直下一步即可, 添加用户 添加域管理员 将普通用户添加到Domain Admins里

  3. leetcode78.子集➕90.子集2

    78子集 dfs dfs1: 和全排列的区别就是对于当前考察的索引i,全排列如果不取i,之后还要取i,所以需要一个visited数组用来记录.对于子集问题如果不取i,之后也不必再取i. 单纯递归回溯 ...

  4. 在远程连接mysql数据库出现问题怎么办

    远程连接mysql数据库报“Communications link failure...”错误 今天在用myEclipse连接时提示:Communications link failure,Last ...

  5. AcWing 840. 模拟散列表

    拉链法 #include<cstring> #include<iostream> using namespace std ; ; int h[N],e[N],ne[N],idx ...

  6. 吴裕雄 python 机器学习——核化PCAKernelPCA模型

    # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datas ...

  7. 1042B. Vitamins

    Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set o ...

  8. Dart语言学习(八) dynamic

    dynamic 表示是动态的,数据类型是指任意类型 var a; a = ; a = "Dart"; print(a); dynamic b = ; b = "JavaS ...

  9. Python3 post 嵌套json

    目录 python3 post json burpsuite 抓取 python requests 数据包 小结 python3 post json 前些天python3 post出现的小问题做下记录 ...

  10. 消息队列(二)--- RocketMQ-NameServer阅读

    概述   所有broker在启动的时候都会向NameServer进行注册,对它进行发送心跳包. 源码阅读 我们先从 NamesrvStartup这个类分析 public static void mai ...