URAL 1992 CVS 链表
不更改链表结构,只是添加节点,没有删除节点。通过记录和更改标记来模拟题意的插入和删除,复制
指针模拟链表:
预开指针,存在M[]中,可以提高效率
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include <stack>
#define REP(i, n) for(int i=0; i<n; i++)
#define PB push_back
#define LL long long
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std; const int maxn = 500005; struct point{
int val;
point *pre;
}M[maxn * 2];
int tot;
struct node{
point *a, *b;
}c[maxn]; void add(point* &pre, int y)
{
point *u = &M[tot++];
u->val = y;
u->pre = pre;
pre = u;
}
void del(point* &last)
{
last = last->pre;
}
int t, m, n; int main()
{
char op[12];
tot = 1;
n = 1;
int x, y;
scanf("%d%d", &t, &m); while (t--)
{
scanf("%s", op);
scanf("%d", &x);
if (op[0] == 'l')
{
scanf("%d", &y); add(c[x].a, y);
c[x].b = NULL;
}
else if (op[0] == 'r' && op[1] == 'o')
{
if (c[x].a)
{
add(c[x].b, c[x].a->val);
del(c[x].a);
}
}
else if (op[0] == 'r' && op[1] == 'e')
{
if (c[x].b)
{
add(c[x].a, c[x].b->val);
del(c[x].b);
}
}
else if (op[0] == 'c' && op[1] == 'l')
{
c[++n] = c[x];
}
else
{
if (!c[x].a) printf("basic\n");
else printf("%d\n", c[x].a->val);
}
}
}
数组模拟链表:
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include <stack>
#define REP(i, n) for(int i=0; i<n; i++)
#define PB push_back
#define LL long long
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std; const int maxn = 500005; struct point{
int val;
int pre;
}P[maxn * 2]; struct node{
int a, b;
node(){}
node(int a, int b) : a(a), b(b){}
}c[maxn];
int tot; int t, m, n; void add(int u, int &pre, int y)
{
P[tot].pre = pre;
P[tot].val = y;
pre = tot++;
} void del(int &last)
{
last = P[last].pre;
} int main()
{
char op[12];
n = 1;
tot = 1;
int x, y;
scanf("%d%d", &t, &m); while (t--)
{
scanf("%s", op);
scanf("%d", &x);
if (op[0] == 'l')
{
scanf("%d", &y); add(x, c[x].a, y);
c[x].b = 0;
}
else if (op[0] == 'r' && op[1] == 'o')
{
if (c[x].a)
{
add(x, c[x].b, P[c[x].a].val);
del(c[x].a);
}
}
else if (op[0] == 'r' && op[1] == 'e')
{
if (c[x].b)
{
add(x, c[x].a, P[c[x].b].val);
del(c[x].b);
}
}
else if (op[0] == 'c' && op[1] == 'l')
{
c[++n] = node(c[x].a, c[x].b);
}
else
{
if (!c[x].a) printf("basic\n");
else printf("%d\n", P[c[x].a].val);
}
}
}
URAL 1992 CVS 链表的更多相关文章
- URAL 1992 CVS
CVS 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1992 Description Yoda: Visit I will the c ...
- URAL 1992 CVS 可持久化链栈
http://www.cnblogs.com/tedzhao/archive/2008/11/12/1332112.html 看这篇的链表部分的介绍应该就能理解“可持久化”了 动态分配内存的会T,只能 ...
- URAL 1992
CVS Description Yoda: Visit I will the cloners on Kamino... And see this army they have created for ...
- ural 1269. Obscene Words Filter
1269. Obscene Words Filter Time limit: 0.5 secondMemory limit: 8 MB There is a problem to check mess ...
- URAL题解二
URAL题解二 URAL 1082 题目描述:输出程序的输入数据,使得程序输出"Beutiful Vasilisa" solution 一开始只看程序的核心部分,发现是求快排的比较 ...
- Redis链表实现
链表在 Redis 中的应用非常广泛, 比如列表键的底层实现之一就是链表: 当一个列表键包含了数量比较多的元素, 又或者列表中包含的元素都是比较长的字符串时, Redis 就会使用链表作为列表键的底层 ...
- [数据结构]——链表(list)、队列(queue)和栈(stack)
在前面几篇博文中曾经提到链表(list).队列(queue)和(stack),为了更加系统化,这里统一介绍着三种数据结构及相应实现. 1)链表 首先回想一下基本的数据类型,当需要存储多个相同类型的数据 ...
- 排序算法----基数排序(RadixSort(L))单链表智能版本
转载http://blog.csdn.net/Shayabean_/article/details/44885917博客 先说说基数排序的思想: 基数排序是非比较型的排序算法,其原理是将整数按位数切割 ...
- 版本控制工具比较-CVS,SVN,GIT
首先介绍几个版本控制软件相互比较的重要依据: a.版本库模型(Repository model):描述了多个源码版本库副本间的关系,有客户端/服务器和分布式两种模式.在客户端/服务器模式下,每一用户通 ...
随机推荐
- Oracle客户端PL_SQL的安装
Oracle数据库的操作大多还是在客户端完成的,因此在众多的客户端软件中我选择了PL_SQL,一下谈谈PL_SQL的基本安装和操作,以及在操作中碰到的一些问题: 1. 首先下载PL_SQL客户端软件, ...
- 解决Linux/aix 下的websphere log4j不生效
websphere 解决Linux/aix下的log4j不生效 在目录: /IBM/WebSphere/AppServer/profiles/AppSrv01/properties 增加一个文件:可以 ...
- StatsD!次世代系统监控的核心
在互联网业务蒸蒸日上的今时今日,系统架构日渐复杂,随着软件产品和工程团队的变革,许多开源的监控工具应运而生,其中有一些相当出名,比如 Zabbix.Nagios 还有 StatsD.也有一些问题被大家 ...
- android 自定义标题栏 titleBar自定义
在value文件夹下添加style.xml <?xml version="1.0" encoding="utf-8"?> <resources ...
- UVA_11468_Substring_(AC自动机+概率动态规划)
描述 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- Xcode7工程改名
0: 先把原工程压缩个zip包备份一份. 1:在Project navigator中, 选择旧工程名字, 再次点击, 修改. 会弹出提示框. 直接点击确认. (Xcode7.1.1中经常导致Xcode ...
- LightOJ 1138 Trailing Zeroes (III) 打表
就是统计5,然后当时因为发现最多有8000w个5的倍数,然后8000w/100,是80w,打表,二分找 然后我看网上的都是直接二分找,真是厉害 #include <cstdio> #inc ...
- 查看ssh服务开启状态
root@dbaudit-desktop:/etc/init.d# /etc/init.d/ssh status * sshd is running 或者这样检查:root@dbaudit-deskt ...
- CentOS下恢复Firefox的复制等功能
在CentOS下使用firefox编辑博客时,我发现无法使用复制粘帖功能,可用如下两种方法恢复(方法一已验证可行): 方法一: 找到user.js所在的目录,Linux下的user.js所在目录为Un ...
- redis命令之lrange
LRANGE key start stop Related commands BLPOP BRPOP BRPOPLPUSH LINDEX LINSERT LLEN LPOP LPUSH LPUSHX ...