URAL 1992 CVS 可持久化链栈
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 可持久化链栈的更多相关文章
- URAL 1992 CVS
CVS 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1992 Description Yoda: Visit I will the c ...
- URAL 1992 CVS 链表
不更改链表结构,只是添加节点,没有删除节点.通过记录和更改标记来模拟题意的插入和删除,复制 指针模拟链表: 预开指针,存在M[]中,可以提高效率 #include<functional> ...
- 03链栈_LinkStack--(栈与队列)
#include "stdio.h" #include "stdlib.h" #include "io.h" #include " ...
- 从零开始学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 ...
- java与数据结构(6)---java实现链栈
栈之链式存储结构链栈 链栈 栈的链式存储结构成为链栈.链栈是没有头结点,头结点就是栈顶指针top. 代码结构 package list; public interface Stackable;公共接口 ...
- 链栈之C++实现
链栈是借用单链表实现的栈.其不同于顺序栈之处在于: 1.链栈的空间是程序运行期间根据需要动态分配的,机器内存是它的上限.而顺序栈则是 静态分配内存的. 2.链栈动态分配内存的特性使得它一般无需考虑栈溢 ...
- C++实现链栈的基本操作
之前对顺序栈写了基本操作,认为有必要也动手练练栈的链表实现. 对于链栈,一般不会出现栈满的情况. 链栈头文件定义例如以下: #ifndef CSTOCK_H_ #define CSTOCK_H_ ty ...
- 【小白成长撸】--链栈(C语言版)
// 链栈.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #include <st ...
- C语言简单实现链栈基本几个功能(适合新手看,大神可指正)
接着上一次的顺序栈,今天我记一下链栈,因为我也是刚学不久,有些地方也稍稍理解不了,所以,一起共勉.我会用我自己结合教材上画的图,争取跟代码一起结合,用文字和图最大化的解释代码,这样的话 ...
随机推荐
- Html注册表单示例
注册表单示例,出自<网页开发手记:Html,CSS,JavaScript实战详解>. <html> <head> <title>注册表单&l ...
- python常用库
本文由 伯乐在线 - 艾凌风 翻译,Namco 校稿.未经许可,禁止转载!英文出处:vinta.欢迎加入翻译组. Awesome Python ,这又是一个 Awesome XXX 系列的资源整理,由 ...
- JavaScript 数组 length 属性获取数组长度或设置数组元素的数目
JavaScript 数组 length 属性 JavaScript 数组 length 属性可返回或设置或组中元素的数目,语法如下: array_object.length 利用 length 属性 ...
- AngularJS 1.2.x 学习笔记(表单校验篇)
https://my.oschina.net/cokolin/blog/526911 摘要: 本文首发于 blog.csdn.net/vipshop_ebs/article/details/39472 ...
- [转帖]FPGA开发工具汇总
原帖:http://blog.chinaaet.com/yocan/p/5100017074 ----------------------------------------------------- ...
- post请求接口
/// <summary> /// post 调用接口 /// </summary> /// <param name="xmlRequest"> ...
- 如何理解JS回调函数
1.回调函数英文解释: A callback is a function that is passed as an argument to another function and is execut ...
- Redis学习手册——转载
转载出处:http://www.cnblogs.com/stephen-liu74/archive/2012/04/16/2370212.html 为什么自己当初要选择Redis作为数据存储解决方案中 ...
- 15.6.2 Configuring the Merge Threshold for index pages[innodb]
MERGE THRESHOLD 提供了可以合并相邻索引page的功能. 默认值是50 如果一个页中数据被删除或者更新减小,导致页中有空白部分,空白部分接近合并门槛的值,则会和相邻页合并, 但是两个pa ...
- vc++ 判断文件或是文件夹是否存在,比较好的做法
#include <windows.h> void main() { //文件或文件夹都可以判断,最后的\\号有无都没关系 !=GetFileAttributes("D:\\My ...