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 ...
随机推荐
- Linux下iptables安全配置
Linux下配置IPTables,只开放特定端口,禁用其他网络. *filter :INPUT DROP [0:0] :FORWARD DROP [0:0] :OUTPUT ACCEPT [0:0] ...
- 实现自己的Promise polyfill
功能清单: Promise.prototype.then() Promise.prototype.catch() Promise.reject() Promise.resolve() Promise. ...
- linux上抓包
使用tcpdump命令. 使用tcpdump -help查看其用法. -i eth0:在第一块网卡上进行抓包. -w filename.cap:将抓的保存到当前目录下的filename.cap文件中, ...
- 51Nod 1091 线段重叠 | 贪心
Input示例 5 1 5 2 4 2 8 3 7 7 9 Output示例 4 first try: O(n^2):二层循环,减法取最大 后五个time limit exceeded #includ ...
- Java面试题整理二
一.io有几种流? 有两种流:字节流和字符流. 字节流继承自inputstream和outstream. 字符流继承自write和read. 二.Jdbc的开发流程? JDBC编程的六个步骤: 1)加 ...
- Xamarin入门浅析
1. 安装 1) 使用标准安装流程(JDK1.6 -> Android SDK -> NDK -> Xamarin Studio -> Xamarin Visual Studi ...
- Centos下Mysql密码忘记解决办法
1.修改MySQL的登录设置: # vim /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 例如: [mysqld] datadir=/var/lib/m ...
- Linux SSH 无密码登录
1. ssh-keygen -t rsa 2. scp root@ip:/root/.ssh/id_rsa.pub ./id2 3. cat id2 >> authtorized_keys ...
- bzoj3043 IncDec Sequence
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3043 [题解] 比较神奇的一道题,开始没往差分的角度上想,所以没想出来. 考虑查分数组,有$ ...
- st2-045漏洞利用poc
use LWP::UserAgent; undef $/; ){print "Use:poc.pl http://target/index.action\n";exit;} my ...