ZOJ - 4016

vector又T又M

list是以链表的方式存储的 是一个双向链表

元素转移操作中,不能一个个遍历加入到s中,list独有的splic函数可以在常数时间内实现合并(并删除源list)

splice()有三种调用形式:
第一种: list1.splice(it1, list2).将list2中的所有元素拷贝到list1中。在list1中的起始位置是it1.复制结束后,list2将为空。

第二种调用形式:
list1.splice(it1, list2, it2)
这个功能是将list2中的元素,从it2开始,剪切到list1的it1起始的地方。

第三种调用形式:
list1.splice(it1, list2, it2begin, it2end)

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff; list<int> G[maxn]; int main()
{
int T;
rd(T);
while(T--)
{
int n, q;
rd(n), rd(q);
for(int i = ; i <= n; i++) G[i].clear();
for(int i = ; i < q; i++)
{
int id, v, s, t;
rd(id);
if(id == )
{
rd(s), rd(v);
G[s].push_back(v);
}
else if(id == )
{
rd(s);
if(G[s].empty())
{
printf("EMPTY\n");
continue;
}
printf("%d\n", G[s].back());
G[s].pop_back();
}
else
{
rd(s), rd(t);
// for(list<int>::iterator it = G[t].begin(); it != G[t].end(); it++)
// G[s].push_back(*it);
// G[t].clear();
G[s].splice(G[s].end(), G[t]);
} } } return ;
}

Mergeable Stack ZOJ - 4016(list)的更多相关文章

  1. Mergeable Stack(链表实现栈)

    C - Mergeable Stack ZOJ - 4016 一开始用stl中内置的栈来写,其中第三个操作,我先复制到一个数组,再将其倒给另一个栈 这个方法有两个错误的地方: 1.栈在内存很大需要扩容 ...

  2. ZOJ 4016 Mergeable Stack(利用list模拟多个栈的合并,STL的应用,splice函数!!!)

    Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given initially empty stacks, ther ...

  3. ZOJ 4016 Mergeable Stack(栈的数组实现)

    Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given  initially empty stacks, the ...

  4. ZOJ 4016 Mergeable Stack 链表

    Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given  initially empty stacks, the ...

  5. C Mergeable Stack(list超好用)

    ZOJ  4016 list用法https://www.cnblogs.com/LLLAIH/p/10673068.html 一开始用普通的栈做,超内存,链表模拟栈也没写出来orz.补题发现list超 ...

  6. ZOJ - 4016 Mergeable Stack 【LIST】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 题意 模拟栈的三种操作 第一种 push 将指定元素压入指 ...

  7. ZOJ - 4016 Mergeable Stack (STL 双向链表)

    [传送门]http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 [题目大意]初始有n个空栈,现在有如下三种操作: (1) ...

  8. ZOJ 4016 Mergeable Stack(from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)

    模拟题,用链表来进行模拟 # include <stdio.h> # include <stdlib.h> typedef struct node { int num; str ...

  9. [ZOJ 4016] Mergable Stack

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 直接用栈爆内存,看网上大神用数组实现的,构思巧妙,学习了! ...

随机推荐

  1. sql学习笔记(三)—— 联表查询

    上篇写了一些sql查询的知识,这篇接着写一下有关联表查询的知识. 既然是联表查询,那肯定得多个表啊,所以,我们先创建一个教师表,表名为 teacher,并且向表中插入数据. 准备工作: 创建表语句: ...

  2. 纯CSS打造淘宝导航菜单栏

    店铺装修-PC端-基础页-首页-装修页面:编辑“菜单”模块-显示设置,粘贴如下CSS: /* 导航条背景色*/ .skin-box-bd .menu-list{background: none rep ...

  3. js正则表达式替换HTML标签以及空格(&nbsp;)

    参考:范仁义 js代码: function filter(text) { var reg = /<[^<>]+>/g;//1.全局匹配g肯定忘记写,2.<>标签中不 ...

  4. Java基础-异常、断言

    处理错误 如果Java程序运行期间出现了错误,并且由于出现错误导致某些操作没有完成,程序应该能够返回到一种安全状态,并能够让用户执行一些其他的命令:或者允许用户保存所有操作结果,并以妥善的方式终止程序 ...

  5. MySQL 字符集和校对

    字符集是指一种从二进制编码到某类字符符号的映射,校对是一组用于某个字符集的排序规则.每一类编码字符都有其对应的字符集和校对规则 MySQL 如何使用字符集 每种字符集都可能有多种校对规则,并且都有一个 ...

  6. Sublime Text3介绍和插件安装——基于Python开发

    Subime编辑器是一款轻量级的代码编辑器,是收费的,但是可以无限期使用.官网下载地址:https://www.sublimetext.com. Sublime Text3支持语言开发种类多样,几乎可 ...

  7. 《JavaScript高级程序设计》笔记:使用Canvas绘图(15)

    基本用法 要使用<canvas>元素,必须先设置其width和height属性,指定可以绘图的区域大小.出现在开始和结束标签中的内容是后备信息,如果浏览器不支持<canvas> ...

  8. (五) Keras Adam优化器以及CNN应用于手写识别

    视频学习来源 https://www.bilibili.com/video/av40787141?from=search&seid=17003307842787199553 笔记 Adam,常 ...

  9. Android远程桌面助手(B1332)之文件管理器

    Android远程桌面助手除了支持Android界面的显示及控制外,还支持Android文件系统的管理,包括文件的快速上传(push).下拉(pull)和查看(cat). Android远程桌面助手( ...

  10. selenium-日志文件的使用(十二)

    概述 在自动化测试中,如果测试失败需要对错误的错误的代码或者测试case进行分析,进行分析时最好的方法是在项目中添加日志文件,通过日志文件的分析定位出现错误的原因. 这样可以保持自动化测试用例的健壮性 ...