L2-002. 链表去重

因为数值比较小,所以直接用数组来模拟

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std; #define maxn 100005 struct node
{
int key;
int next;
}a[maxn]; int main()
{
int first,n,add;
scanf("%d%d",&first,&n);
for(int i=;i<n;i++)
{
scanf("%d",&add);
scanf("%d%d",&a[add].key,&a[add].next);
} //去重:直接再开两个数组记录去重后两个链表的地址
int num,vis[]={},t1=,t2=;
int a1[maxn],a2[maxn];
for(int i=first;i!=-;i=a[i].next)
{
num=abs(a[i].key);
if(!vis[num])
{
vis[num]=;
a1[t1++]=i;
}
else
a2[t2++]=i; } printf("%05d %d ",a1[],a[a1[]].key);
for(int i=;i<t1;i++)
{
printf("%05d\n",a1[i]);
printf("%05d %d ",a1[i],a[a1[i]].key);
}
printf("-1\n"); if(t2)
{
printf("%05d %d ",a2[],a[a2[]].key);
for(int i=;i<t2;i++)
{
printf("%05d\n",a2[i]);
printf("%05d %d ",a2[i],a[a2[i]].key);
}
printf("-1\n");
} return ;
}

L2-002. 链表去重(数组模拟)的更多相关文章

  1. L2-002. 链表去重(模拟)

    题意: 给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值有重复的结点.即对任意键值K,只有键值或其绝对值等于K的第一个结点可以被保留.同时,所有被删除的结点必须被保存在另外一个链 ...

  2. 【数组模拟的链表or复杂模拟】PAT-L2-002. 链表去重

    L2-002. 链表去重 给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值有重复的结点.即对任意键值K,只有键值或其绝对值等于K的第一个结点可以被保留.同时,所有被删除的结点必须 ...

  3. Problem UVA12657-Boxes in a Line(数组模拟双链表)

    Problem UVA12657-Boxes in a Line Accept: 725  Submit: 9255 Time Limit: 1000 mSec Problem Description ...

  4. UVA11988-Broken Keyboard(数组模拟链表)

    Problem UVA11988-Broken Keyboard Accept: 5642  Submit: 34937 Time Limit: 1000 mSec Problem Descripti ...

  5. C - Boxes in a Line 数组模拟链表

    You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simul ...

  6. B - Broken Keyboard (a.k.a. Beiju Text) 数组模拟链表

    You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...

  7. UVa 12657 Boxes in a Line(数组模拟双链表)

    题目链接 /* 问题 将一排盒子经过一系列的操作后,计算并输出奇数位置上的盒子标号之和 解题思路 由于数据范围很大,直接数组模拟会超时,所以采用数组模拟的链表,left[i]和right[i]分别表示 ...

  8. POJ - 3476 A Game with Colored Balls---优先队列+链表(用数组模拟)

    题目链接: https://cn.vjudge.net/problem/POJ-3476 题目大意: 一串长度为N的彩球,编号为1-N,每个球的颜色为R,G,B,给出它们的颜色,然后进行如下操作: 每 ...

  9. 数组模拟单向链表例题(UVa11988)

    指针的链表实现方式是,当前节点的next指向下一个节点,用数组模拟就是 for(int i=next[0];i!=0;i=next[i]) i=next[i]:就是一条链. 例题: 你有一个破损的键盘 ...

随机推荐

  1. windows中安装liunx虚拟机

    我感觉这个写的很好,所以本内容是转他人的内容. http://www.csdn.net/article/2015-06-05/2824882/1

  2. 用swoole简单实现MySQL连接池

    MySQL连接池 在传统的网站开发中,比如LNMP模式,由Nginx的master进程接收请求然后分给多个worker进程,每个worker进程再链接php-fpm的master进程,php-fpm再 ...

  3. PostgreSQL查看表大小的命令

    SELECT table_name, pg_size_pretty(table_size) AS table_size, pg_size_pretty(indexes_size) AS indexes ...

  4. Hadoop 2.7.3 完全分布式维护-动态增加datanode篇

    原有环境 http://www.cnblogs.com/ilifeilong/p/7406944.html  IP       host JDK linux hadop role 172.16.101 ...

  5. webmagic 日志使用及maven项目中排除日志依赖

    我用的Spring Boot maven构建的工程,默认引入了 <dependency> <groupId>org.springframework.boot</group ...

  6. npm使用过程中出现的错误

    1.安装npm install axios -S报错install "npm ERR! Error: EPERM: operation not permitted" error 经 ...

  7. 静态HTML总结

    第一章<META>标签: <meta http-equiv=”Content-Type” Content=”text/html;charset=gb2312”>------避免 ...

  8. windows 文本操作

    type命令 作用:显示文件类文件内容 (例如:.txt .Java .cpp .c .html 等属于文本类文件 .word excel ppt exe dll 等都不属于文本类文件) fc命令 作 ...

  9. unity中把一个图片切割成两个UI图片

    1.在unity3D的Project视图下选中需要更改的图片,将图片的Texture Type更改为Sprite (2D and UI),点击Apply即可.操作如图所示: 2.完成步骤一,点击App ...

  10. Linux防火墙iptables的策略

    iptables策略 iptables -L #查看现有防火墙所有策略 iptables -F #清除现有防火墙策略 只允许特定流量通过,禁用其他流量 1.允许SSH流量(重要) iptables - ...