题意:模拟栈,正常pop,push,多一个merge A B 形象地说就是就是将栈B堆到栈A上。

题解:直接用list 的pop_back,push_back,splice 模拟,

坑:用splice,第一次超时,正要大改 发现是cin超时。。。

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<cstring>
#include<set>
#include<algorithm>
#include<stack>
#include<string>
#include<cstdio>
#include<list>
#define _for(i, a, b) for (int i = (a); i<(b); ++i)
using namespace std;
const int N = 3e5 + ;
const int INF = 1e6;
list<int> v[N]; int main()
{
int t;
cin >> t;
while (t--) {
int n, q; int a, b; cin >> n >> q;
_for(i, , n + )v[i].clear();
while (q--) {
int x;
scanf("%d", &x);
if (x == ) {
scanf("%d%d", &a, &b);
v[a].push_back(b);
}
if (x == ) {
int b; scanf("%d", &b);
if (v[b].empty())printf("EMPTY\n");
else {
printf("%d\n", v[b].back());
v[b].pop_back();
} }
if (x == ) {
scanf("%d%d", &a, &b);
v[a].splice(v[a].end(), v[b]);
}
}
}
//system("pause");
return ;
}

Mergeable Stack 直接list内置函数。(152 - The 18th Zhejiang University Programming Contest Sponsored by TuSimple)的更多相关文章

  1. The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack

    题目链接 题意: 题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!! 代码: #include <std ...

  2. 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 ...

  3. 152 - - G Traffic Light 搜索(The 18th Zhejiang University Programming Contest Sponsored by TuSimple )

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5738 题意 给你一个map 每个格子里有一个红绿灯,用0,1表示 ...

  4. 性能测试总结工作总结-基于WebService协议脚本 内置函数手动编写

    LoadRunner基于WebService协议脚本 WebService协议脚本有三种生成方式,一种是直接通过LoadRunner导入URL自动解析生成:一种是使用LoadRunner内置函数手动编 ...

  5. [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数

    Built-in Operators Relational Operators The following operators compare the passed operands and gene ...

  6. Day3 - Python基础3 函数、递归、内置函数

    Python之路,Day3 - Python基础3   本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8. ...

  7. Orace内置函数大全[转:http://www.cnblogs.com/lfx0692/articles/2395950.html]

    NewProgramer   Oracle SQL 内置函数大全(转) SQL中的单记录函数 1.ASCII 返回与指定的字符对应的十进制数;SQL> select ascii('A') A,a ...

  8. python全栈开发-Day12 三元表达式、函数递归、匿名函数、内置函数

    一. 三元表达式 一 .三元表达式 仅应用于: 1.条件成立返回,一个值 2.条件不成立返回 ,一个值 def max2(x,y): #普通函数定义 if x > y: return x els ...

  9. Python入门之三元表达式\列表推导式\生成器表达式\递归匿名函数\内置函数

    本章目录: 一.三元表达式.列表推导式.生成器表达式 二.递归调用和二分法 三.匿名函数 四.内置函数 ================================================ ...

随机推荐

  1. SQLServer------备份与还原

    转载: http://www.cnblogs.com/zgqys1980/archive/2012/07/04/2576382.html

  2. spring定时任务详解(@Scheduled注解)多线程讲解

    (一)在xml里加入task的命名空间 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns ...

  3. ios开发之--字符串局部改变颜色

    改变指定位置字符的颜色,代码如下: NSString *descStr = @"楼主"; NSString *nickStr = [NSString stringWithForma ...

  4. Java类文件结构

    一.概述 实现语言无关性的基础是虚拟机和字节码存储格式.Java虚拟机不和包括Java在内的任何语言绑定,只与"Class文件"这种特定的二进制文件所关联,Class文件中包含了J ...

  5. DataGridview的自动排序设置

    如图,自动排序是每一列的属性,而不是整个datagridview的属性,之前一直在datagridview的属性中找不到,原来是在列的属性中

  6. struts1的配置文件详解11111

    要想使用Struts,至少要依靠两个配置文件:web.xml和struts-config.xml.其中web.xml用来安装Struts框架.而struts-config.xml用来配置在Struts ...

  7. js replace replaceAll

    今天因为一些原因来看这篇博文,测试了一下根本不对.replace根本没有string.replace("字符","字符")这样的写法,而是stringObjec ...

  8. Android Studio中R报错(cnanot resolve symbol R)

    我的解决办法: Tools -> Android -> Sync Project with Gradle Files Build -> Clean Project 然后就好了 PS: ...

  9. 【python】flask 开启 debug 模式

    方法一: 直接在run的时候添加debug from flask import Flask app = Flask(__name__) @app.route('/') def hello_world( ...

  10. C++空类

    class Empty { public: Empty(); // 缺省构造函数 Empty( const Empty& ); // 拷贝构造函数 ~Empty(); // 析构函数 Empt ...