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. NHibernate系列文章二十八:NHibernate Mapping之Auto Mapping(附程序下载)

    摘要 上一篇文章介绍了Fluent NHibernate基础知识.但是,Fluent NHibernate提供了一种更方便的Mapping方法称为Auto Mapping.只需在代码中定义一些Conv ...

  2. python 序列化 json pickle

    python的pickle模块实现了基本的数据序列和反序列化.通过pickle模块的序列化操作我们能够将程序中运行的对象信息保存到文件中去,永久存储:通过pickle模块的反序列化操作,我们能够从文件 ...

  3. What is Agile

    Agile is a set of Values, Principles and Practices, that will change your behavior to will create gr ...

  4. java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver 错误的解决办法

    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver 错误的解决办法 (2011-05-05 16:08:05) 转载▼ ...

  5. mysql卸载(转)

    按以下步骤卸载mysql server 主要步骤: 1. 停止服务MySQL 2. 卸载mysql相关的程序 3. 删除注册表(运行->regedit),machine->system-& ...

  6. Windows下安装Nginx反向代理服务器

    一,首先到 Nginx官方网站下载最新版本,下载网址: http://nginx.org/en/download.html 二,解压ZIP包,目录修改为nginx.放置在D盘根目录下,也可以放置在其它 ...

  7. 动态加载script文件的两种方法

    第一种就是利用ajax方式,把script文件代码从后台加载到前台,然后对加载到的内容通过eval()执行代码.第二种是,动态创建一个script标签,设置其src属性,通过把script标签插入到页 ...

  8. lnmp

    参照http://www.osyunwei.com/archives/8867.html,略有改动 一 .系统约定 软件源代码包存放位置:/usr/local/src 源码包编译安装位置:/usr/l ...

  9. sys模块和os模块,利用sys模块生成进度条

    sys模块import sysprint(sys.argv)#sys.exit(0)             #退出程序,正常退出exit(0)print(sys.version)       #获取 ...

  10. 基于VLC的视频播放器(转载)

    最近在研究视频播放的功能,之前是使用VideoView.在网上看了一下,感觉不是很好,支持的格式比较少,现在网络视频的格式各种各样,感觉用VideoView播放起来局限性很大. 找到了一个比较合适的播 ...