The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack
题目链接
题意:
题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!!
代码:
#include <stdio.h>
#include <iostream>
#include <vector>
#include <deque>
#include <list>
#define IO ios::sync_with_stdio(0);\
cin.tie();cout.tie();
using namespace std;
*+;
list <int > q[N];
int main()
{
int T;
scanf("%d",&T);
//cin >> T;
while(T--)
{
int n,q1;
scanf("%d%d",&n,&q1);
; i <= n; i++)
q[i].clear();
while(q1--)
{
int op,s,v,t;
scanf("%d",&op);
)
{
scanf("%d%d",&s,&v);
q[s].push_back(v);
}
)
{
scanf("%d",&s);
if(q[s].empty())
{
//cout << "EMPTY" << endl;
printf("%s\n", "EMPTY");
}
else
{
//cout << q[s].back() <<endl;
printf("%d\n",q[s].back());
q[s].pop_back();
}
}
)
{
scanf("%d%d",&s,&t);
q[s].splice(q[s].end(),q[t]); //将s,t合并,并清除t中元素
//q[t].clear();
}
}
}
;
}
The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack的更多相关文章
- zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)
题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...
- Mergeable Stack 直接list内置函数。(152 - The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
题意:模拟栈,正常pop,push,多一个merge A B 形象地说就是就是将栈B堆到栈A上. 题解:直接用list 的pop_back,push_back,splice 模拟, 坑:用splice ...
- 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表示 ...
- The 18th Zhejiang University Programming Contest Sponsored by TuSimple
Pretty Matrix Time Limit: 1 Second Memory Limit: 65536 KB DreamGrid's birthday is coming. As hi ...
- 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 ...
- ZOJ 4019 Schrödinger's Knapsack (from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
题意: 第一类物品的价值为k1,第二类物品价值为k2,背包的体积是 c ,第一类物品有n 个,每个体积为S11,S12,S13,S14.....S1n ; 第二类物品有 m 个,每个体积为 S21,S ...
- The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror) B"Even Number Theory"(找规律???)
传送门 题意: 给出了三个新定义: E-prime : ∀ num ∈ E,不存在两个偶数a,b,使得 num=a*b;(简言之,num的一对因子不能全为偶数) E-prime factorizati ...
- The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391 A Thanks, TuSimple! Time ...
- The 17th Zhejiang University Programming Contest Sponsored by TuSimple J
Knuth-Morris-Pratt Algorithm Time Limit: 1 Second Memory Limit: 65536 KB In computer science, t ...
随机推荐
- POJ 3254 状态压缩 DP
B - Corn Fields Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:65536KB ...
- cas 服务端、客服端详细配置
一.准备 1.下载官方源码 CAS-Server下载地址:https://www.apereo.org/projects/cas/download-cas CAS-Client下载地址:http:// ...
- java mysql 连接
第一种: //驱动程序名 String driver = "com.mysql.jdbc.Driver"; //URL指向要访问的数据库名mydata String url = & ...
- MyBatis框架的使用及源码分析(五) DefaultSqlSessionFactory和DefaultSqlSession
我们回顾<MyBatis框架中Mapper映射配置的使用及原理解析(一) 配置与使用> 一文的示例 private static SqlSessionFactory getSessionF ...
- 【BZOJ】1609: [Usaco2008 Feb]Eating Together麻烦的聚餐
[算法]动态规划 [题解]DP有个特点(递推的特点),就是记录所有可能状态然后按顺序转移. 最优化问题中DP往往占据重要地位. f[i][j]表示前i头奶牛,第i头改为号码j的最小改动数字,这样每头奶 ...
- 超详细的Java面试题总结(三)之Java集合篇常见问题
List,Set,Map三者的区别及总结 List:对付顺序的好帮手 List接口存储一组不唯一(可以有多个元素引用相同的对象),有序的对象 Set:注重独一无二的性质 不允许重复的集合.不会有多个元 ...
- 【洛谷 P1390】 公约数的和 (欧拉函数)
题目链接 做过\(n\)遍这种题了... 答案就是\(\sum_{i=1}^{n}\sum_{j=1}^{n/i}[\varphi(j)*i]\) 线筛欧拉函数求前缀和直接算就行. #include ...
- 如何升级nodejs版本 安装n模块报错 npm ERR! notsup Unsupported platform
如何升级nodejs版本 首先安装n模块, 输入npm install -g n n模块专门用来管理nodejs的版本. 如果出现npm ERR! notsup Unsupported platfor ...
- F题 hdu 1431 素数回文
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1431 素数回文 Time Limit: 2000/1000 MS (Java/Others) M ...
- hydra 密码破解工具详解
一.简介 hydra是著名黑客组织thc的一款开源的暴力密码破解工具,可以在线破解多种密码.官 网:http://www.thc.org/thc-hydra,可支持AFP, Cisco AAA, Ci ...