题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805072641245184

第一次做链表题,有时间多看看

解释的话直接看这篇题解:https://www.liuchuo.net/archives/2125

 #include <bits/stdc++.h>
using namespace std;
const int inf=<<;
typedef long long ll;
typedef pair<int,int> P;
const double pi=acos(-);
const int mod=1e8+;
const int maxn=1e5+;
const int maxm=;
struct node{
int adress,val,next,num;
}a[maxn];
bool exist[maxn];
int cnt,cnt1,cnt2;
bool cmp(const node &a,const node &b){
return a.num<b.num;
}
int main(){
int begin,n;scanf("%d%d",&begin,&n);
for(int i=;i<maxn;i++){
a[i].num=*maxn;
}
for(int i=;i<n;i++){
int x,y,z;scanf("%d",&x);
a[x].adress=x;
scanf("%d%d",&a[x].val,&a[x].next);
}
for(int i=begin;i!=-;i=a[i].next){
if(!exist[abs(a[i].val)]){
exist[abs(a[i].val)]=;
a[i].num=cnt1;
cnt1++;
}
else{
a[i].num=cnt2+maxn;
cnt2++;
}
}
cnt=cnt1+cnt2;
sort(a,a+maxn,cmp);
for(int i=;i<cnt;i++){
if(i==cnt1-||i==cnt-) printf("%05d %d -1\n",a[i].adress,a[i].val);
else printf("%05d %d %05d\n",a[i].adress,a[i].val,a[i+].adress);
}
return ;
}

PTA L2-002 链表去重的更多相关文章

  1. pta l2-2(链表去重)

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805072641245184 题意:给定一个链表,要求删除其中键 ...

  2. PTA L2-002 链表去重 团体程序设计天梯赛-练习集

    L2-002 链表去重(25 分)   给定一个带整数键值的链表 L,你需要把其中绝对值重复的键值结点删掉.即对每个键值 K,只有第一个绝对值等于 K 的结点被保留.同时,所有被删除的结点须被保存在另 ...

  3. 天梯 L2 链表去重

    L2-002 链表去重 (25 分) 给定一个带整数键值的链表 L,你需要把其中绝对值重复的键值结点删掉.即对每个键值 K,只有第一个绝对值等于 K 的结点被保留.同时,所有被删除的结点须被保存在另一 ...

  4. pta L2-002 链表去重 +散列表知识小普及+二进制取反补码运算

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805072641245184: 废话:今天忙着学习新知识了,没怎 ...

  5. L2-002 链表去重 (25 分)

    L2-002 链表去重 (25 分)   给定一个带整数键值的链表 L,你需要把其中绝对值重复的键值结点删掉.即对每个键值 K,只有第一个绝对值等于 K 的结点被保留.同时,所有被删除的结点须被保存在 ...

  6. 团体程序设计天梯赛-练习集L2-002. 链表去重

    L2-002. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除 ...

  7. L2-002. 链表去重

    L2-002. 链表去重 题目链接:https://www.patest.cn/contests/gplt/L2-002 这题因为结点地址只有四位数,所以可以直接开一个10000的数组模拟内存就好了. ...

  8. L2-2. 链表去重

    L2-2. 链表去重 时间限制300 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者陈越给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值有重复的 ...

  9. C# 链表去重 List 一维 二维 分别使用 Distinct() GroupBy() 方法

    分别使用List中Distinct(),GroupBy()实现链表的去重. 1.先上效果: 一维链表中分别有元素“aa”,"bb",'aa','aa',"cc" ...

  10. [leetcode]83. Remove Duplicates from Sorted List有序链表去重

    Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...

随机推荐

  1. 如何创建并运行java线程 , 多线程使用

    http://www.importnew.com/20672.html https://www.cnblogs.com/wxd0108/p/5479442.html https://www.cnblo ...

  2. Bytom交易说明(UTXO用户自己管理模式)

    比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom 该部分主 ...

  3. Shell中的IFS

    一.IFS 介绍 Shell 脚本中有个变量叫 IFS(Internal Field Seprator) ,内部域分隔符.完整定义是The shell uses the value stored in ...

  4. 关于在mac安装安卓的模拟器的一些些那点事情~~~

    ook~~自己捣鼓了三天终于安装成功了~妹的~踩了太多的坑~整个人就不好了~ 为了节省大家的时间~所以今天我就将我安装的过程整体思路教给大家!有了思路安装起来就很好了!!!但是 注意的是,也许你会出现 ...

  5. Codeforces 781D Axel and Marston in Bitland

    题目链接:http://codeforces.com/contest/781/problem/D ${F[i][j][k][0,1]}$表示是否存在从${i-->j}$的路径走了${2^{k}} ...

  6. intellij idea 破解教程

    首先呼吁:抵制盗版,抵制盗版,抵制盗版 如果只是个人开发学习用,那么下面的教程可能比较适合你了 有两种方法,第一种:Activate--License server,在License server a ...

  7. P2016 战略游戏

    传送门 思路: 前置知识——普通树D: ▲普通的树形 DP : 设 f [ i ][ 0 ] 表示这个点不取,则它的所有子节点都要取:f [ i ][ 1 ] 表示这个点取,则它的子节点取与不取对之前 ...

  8. Centos7 linux下通过源码安装redis以及使用

    下载redis安装包 wget http://download.redis.io/releases/redis-5.0.3.tar.gz 解压压缩包 tar -zxvf redis-.tar.gz y ...

  9. in_array的三个参数

    needle 待搜索的值. haystack 待搜索的数组. strict 如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 hays ...

  10. Oracle其他简单查询

    范例:查询公司中所有雇员的职位信息 SELECT job FROM emp; 实际在公司里面,一个职位会有多个人员.如果查询全部职位,肯定会存在重复.要消除掉重复,利用DISTINCT完成.(dist ...