http://www.cnblogs.com/tedzhao/archive/2008/11/12/1332112.html

看这篇的链表部分的介绍应该就能理解“可持久化”了

动态分配内存的会T,只能用静态

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std; struct node {
int p;
int next;
};
const int maxn = ;
node nd[maxn * ];
int ha[maxn], hb[maxn];
int c;
int cnt;
void add(int &head, int p) {
nd[cnt].p = p;
nd[cnt].next = head;
head = cnt++;
}
int main() {
int n, m;
while(scanf("%d%d", &n, &m) != EOF) {
c = ;
cnt = ;
ha[c] = -; hb[c] = -;
for(int i = ; i <= n; i++) {
char op[]; scanf("%s", op);
if(strcmp(op, "learn") == ) {
int id, p;
scanf("%d%d", &id, &p);
add(ha[id], p);
hb[id] = -;
} else if(strcmp(op, "rollback") == ) {
int id;
scanf("%d", &id);
add(hb[id], nd[ha[id]].p);
ha[id] = nd[ha[id]].next;
} else if(strcmp(op, "clone") == ) {
int id;
scanf("%d", &id);
c++;
ha[c] = ha[id];
hb[c] = hb[id];
} else if(strcmp(op, "check") == ) {
int id;
scanf("%d", &id);
if(ha[id] == -) {
printf("basic\n");
} else printf("%d\n", nd[ha[id]].p);
} else if(strcmp(op, "relearn") == ) {
int id;
scanf("%d", &id);
add(ha[id], nd[hb[id]].p);
hb[id] = nd[hb[id]].next;
}
}
return ;
}
return ;
}

URAL 1992 CVS 可持久化链栈的更多相关文章

  1. URAL 1992 CVS

    CVS 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1992 Description Yoda: Visit I will the c ...

  2. URAL 1992 CVS 链表

    不更改链表结构,只是添加节点,没有删除节点.通过记录和更改标记来模拟题意的插入和删除,复制 指针模拟链表: 预开指针,存在M[]中,可以提高效率 #include<functional> ...

  3. 03链栈_LinkStack--(栈与队列)

    #include "stdio.h" #include "stdlib.h" #include "io.h" #include " ...

  4. 从零开始学C++之数据封装与抽象:分别用C和C++来实现一个链栈

    下面通过分别用C和C++来实现一个链栈(链表实现),从中体会数据封装抽象的思想: C语言实现:  C++ Code  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  5. java与数据结构(6)---java实现链栈

    栈之链式存储结构链栈 链栈 栈的链式存储结构成为链栈.链栈是没有头结点,头结点就是栈顶指针top. 代码结构 package list; public interface Stackable;公共接口 ...

  6. 链栈之C++实现

    链栈是借用单链表实现的栈.其不同于顺序栈之处在于: 1.链栈的空间是程序运行期间根据需要动态分配的,机器内存是它的上限.而顺序栈则是 静态分配内存的. 2.链栈动态分配内存的特性使得它一般无需考虑栈溢 ...

  7. C++实现链栈的基本操作

    之前对顺序栈写了基本操作,认为有必要也动手练练栈的链表实现. 对于链栈,一般不会出现栈满的情况. 链栈头文件定义例如以下: #ifndef CSTOCK_H_ #define CSTOCK_H_ ty ...

  8. 【小白成长撸】--链栈(C语言版)

    // 链栈.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #include <st ...

  9. C语言简单实现链栈基本几个功能(适合新手看,大神可指正)

            接着上一次的顺序栈,今天我记一下链栈,因为我也是刚学不久,有些地方也稍稍理解不了,所以,一起共勉.我会用我自己结合教材上画的图,争取跟代码一起结合,用文字和图最大化的解释代码,这样的话 ...

随机推荐

  1. 27. Oracle 10g下emctl start dbconsole 报错:OC4J Configuration issue 问题解决

    (dbconsole配置好外面的sqlplus才能连的上服务器上的数据库) 采取重新配置emctl 的方法来解决 [oracle@guohuias3 oracle]$ emca -config dbc ...

  2. Spark学习笔记之SparkRDD

    Spark学习笔记之SparkRDD 一.   基本概念 RDD(resilient distributed datasets)弹性分布式数据集. 来自于两方面 ①   内存集合和外部存储系统 ②   ...

  3. EM算法(2):GMM训练算法

    目录 EM算法(1):K-means 算法 EM算法(2):GMM训练算法 EM算法(3):EM算法运用 EM算法(4):EM算法证明 EM算法(2):GMM训练算法 1. 简介 GMM模型全称为Ga ...

  4. mybatis执行批量更新update

    Mybatis的批量插入这里有http://ljhzzyx.blog.163.com/blog/static/38380312201353536375/.目前想批量更新,如果update的值是相同的话 ...

  5. 解决openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory错误

    问题 在Centos7上编译安装openssl后,运行openssl version出现如下错误: openssl: error while loading shared libraries: lib ...

  6. Visual Studio 2013 always switches source control plugin to Git and disconnect TFS

      A few days ago, I've been facing a strange behavior with Visual Studio 2013.   No matter what solu ...

  7. Redis从基础命令到实战之散列类型(Hash)

    从上一篇的实例中可以看出,用字符串类型存储对象有一些不足,在存储/读取时需要进行序列化/反序列化,即时只想修改一项内容,如价格,也必须修改整个键值.不仅增大开发的复杂度,也增加了不必要的性能开销. 一 ...

  8. bool 类型存在数据库中为 0 和 1

    bool 类型存在数据库中为 0 和 1 但是在程序中应该使用  true 和 false 查询. 例如: bIsStart = 0 在数据中bIsStart为 0 sql 查询的时候,使用:sele ...

  9. mac下webpagetest搭建

    我的server和agent都是在mac上搭建的,所以会和linux下有些不同   一.安装配置Apache和PHP webpagetest需要使用PHP和Apache启动服务.mac默认安装了Apa ...

  10. Dev WPF使用总结

    1.换肤 ThemeManager.ApplicationThemeName = Theme.DXStyle.Name this.UpdateLayout(); //重新布局