PTA L2-002 链表去重
题目链接: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 链表去重的更多相关文章
- pta l2-2(链表去重)
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805072641245184 题意:给定一个链表,要求删除其中键 ...
- PTA L2-002 链表去重 团体程序设计天梯赛-练习集
L2-002 链表去重(25 分) 给定一个带整数键值的链表 L,你需要把其中绝对值重复的键值结点删掉.即对每个键值 K,只有第一个绝对值等于 K 的结点被保留.同时,所有被删除的结点须被保存在另 ...
- 天梯 L2 链表去重
L2-002 链表去重 (25 分) 给定一个带整数键值的链表 L,你需要把其中绝对值重复的键值结点删掉.即对每个键值 K,只有第一个绝对值等于 K 的结点被保留.同时,所有被删除的结点须被保存在另一 ...
- pta L2-002 链表去重 +散列表知识小普及+二进制取反补码运算
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805072641245184: 废话:今天忙着学习新知识了,没怎 ...
- L2-002 链表去重 (25 分)
L2-002 链表去重 (25 分) 给定一个带整数键值的链表 L,你需要把其中绝对值重复的键值结点删掉.即对每个键值 K,只有第一个绝对值等于 K 的结点被保留.同时,所有被删除的结点须被保存在 ...
- 团体程序设计天梯赛-练习集L2-002. 链表去重
L2-002. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除 ...
- L2-002. 链表去重
L2-002. 链表去重 题目链接:https://www.patest.cn/contests/gplt/L2-002 这题因为结点地址只有四位数,所以可以直接开一个10000的数组模拟内存就好了. ...
- L2-2. 链表去重
L2-2. 链表去重 时间限制300 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者陈越给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值有重复的 ...
- C# 链表去重 List 一维 二维 分别使用 Distinct() GroupBy() 方法
分别使用List中Distinct(),GroupBy()实现链表的去重. 1.先上效果: 一维链表中分别有元素“aa”,"bb",'aa','aa',"cc" ...
- [leetcode]83. Remove Duplicates from Sorted List有序链表去重
Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...
随机推荐
- LightOJ 1151 Snakes and Ladders(概率DP + 高斯消元)
题意:1~100的格子,有n个传送阵,一个把进入i的人瞬间传送到tp[i](可能传送到前面,也可能是后面),已知传送阵终点不会有另一个传送阵,1和100都不会有传送阵.每次走都需要掷一次骰子(1~6且 ...
- POJ 1182 食物链(并查集+偏移向量)题解
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 82346 Accepted: 24616 Description ...
- Module controller in JMeter
https://qualibrate.com/blog/quality-assurance/jmeter-module-controller/ 通过组合Test Fragments 和Module C ...
- Windows FindFirstFile利用
目前大多数程序都会对上传的文件名加入时间戳等字符再进行MD5,然后下载文件的时候通过保存在数据库里的文件ID读取文件路径,一样也实现了文件下载,这样我们就无法直接得到我们上传的webshell文件路径 ...
- (转) The Incredible PyTorch
转自:https://github.com/ritchieng/the-incredible-pytorch The Incredible PyTorch What is this? This is ...
- (转载)Navicat Premium 12.1.16.0安装与激活
声明:本文所提供的所有软件均来自于互联网,仅供个人研究和学习使用,请勿用于商业用途,下载后请于24小时内删除,请支持正版! 本文介绍Navicat Premium 12的安装.激活与基本使用.已于20 ...
- 剥开比原看代码09:通过dashboard创建密钥时,前端的数据是如何传到后端的?
作者:freewind 比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchai ...
- Ubuntu 14.04 安装sublime
参考 How do I install Sublime Text 2/3? Ubuntu 14.04 安装sublime 通过apt-get包管理器安装sublime. sublime2.0: sud ...
- js转义和反转义html
本文地址: http://www.cnblogs.com/daysme/p/7100553.html 下面的代码网上常用有,但不是想要的. JS实现HTML标签转义及反转义 http://blog.c ...
- 在GeoServer里设置图层的默认自定义样式,出现不显示预览图的情况(不起作用)
在GeoServer里设置图层的默认自定义样式 点击"Layers-->world:country"图层,点击"Publishing"标签,在下面的&qu ...