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 ...
随机推荐
- 在Jenkins中集成Sonarqube
Analyzing with SonarQube Scanner for MSBuild Global Configuration This step is mandatory if you want ...
- 这几道Java集合框架面试题几乎必问
Arraylist 与 LinkedList 异同 补充:数据结构基础之双向链表 ArrayList 与 Vector 区别 HashMap的底层实现 JDK1.8之前 JDK1.8之后 HashMa ...
- hihoCoder week1 最长回文子串
题目链接 https://hihocoder.com/contest/hiho1/problem/1 做法 Manacher #include <bits/stdc++.h> using ...
- tomcat使用spring-loaded实现应用热部署
springloaded官方说明: Spring Loaded is a JVM agent for reloading class file changes whilst a JVM is runn ...
- Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'zoneId' in 'class java.lang.String'
本文为博主原创,未经允许不得而转载: 异常展示: dao层定义的接口为: public int getClientTotal(); 在mybatis中的sql为: <select id=&quo ...
- Git stash 常用命令
参考: Git: How to look at the stash Git学习笔记05--git stash Git stash 常用命令 1.git stash: 保存当前的工作进度: 2.git ...
- toggle 1.9 以后就被删除了
toggle 1.9 以后就被删除了, 1.8.x 以前可用. $(function(){ $(".p_title").toggle( function(){ $(this).n ...
- ngui处理不规则按钮点击
吐个槽 棋牌类游戏做什么中国地图!!! 然后就要用到不规则按钮点击了 你懂的 213的unity虽然已经加入了polygoncollider 2d的支持 但是 但是 但是 是2d的 也就是说如果不 ...
- Tarjan模板题——牛的舞会
题目描述 约翰的N (2 <= N <= 10,000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别 上鲜花,她们要表演圆舞. 只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一 ...
- Windows下pipenv将虚环境文件的位置设置在项目根目录下
在windows下使用pipenv shell时,虚拟环境文件夹会在C:\Users\Administrator\.virtualenvs\目录下默认创建,为了方便管理,将这个虚环境的文件的位置更改一 ...