Open Judge 3339 List
3339:List
- 总时间限制:
- 4000ms
- 内存限制:
- 65536kB
- 描述
-
写一个程序完成以下命令:
new id ——新建一个指定编号为id的序列(id<10000)
add id num——向编号为id的序列加入整数num
merge id1 id2——合并序列id1和id2中的数,并将id2清空
unique id——去掉序列id中重复的元素
out id ——从小到大输出编号为id的序列中的元素,以空格隔开 - 输入
- 第一行一个数n,表示有多少个命令( n<=200000)。以后n行每行一个命令。
- 输出
- 按题目要求输出。
- 样例输入
-
16
new 1
new 2
add 1 1
add 1 2
add 1 3
add 2 1
add 2 2
add 2 3
add 2 4
out 1
out 2
merge 1 2
out 1
out 2
unique 1
out 1 - 样例输出
-
1 2 3
1 2 3 4
1 1 2 2 3 3 4 1 2 3 4#include <cstdio>
#include <iostream>
#include <cstring>
#include <list>
#include <map>
using namespace std; map<int,list<int> > m; int n,x,y;
char op[];
int main(){
scanf("%d",&n);
while(n--){
scanf("%s",op);
if(strcmp(op,"new")==){
scanf("%d",&x);
m.insert(map<int,list<int> >::value_type(x,list<int>()));
}
if(strcmp(op,"add")==){
scanf("%d%d",&x,&y);
m[x].push_back(y);
}
if(strcmp(op,"merge")==){
scanf("%d%d",&x,&y);
m[x].merge(m[y]);
//m[y].clear();
}
if(strcmp(op,"unique")==){
scanf("%d",&x);
m[x].sort();
m[x].unique();
}
if(strcmp(op,"out")==){
scanf("%d",&x);
m[x].sort();
list<int>::iterator it;
for(it=m[x].begin();it!=m[x].end();it++){
printf("%d ",*it);
}
printf("\n");
}
}
}竟然还有list这STL,长见识了真是~~唉~~
Open Judge 3339 List的更多相关文章
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
- BZOJ 3339 & 莫队+"所谓的暴力"
题意: 给一段数字序列,求一段区间内未出现的最小自然数. SOL: 框架显然用莫队.因为它兹瓷离线. 然而在统计上我打了线段树...用&维护的结点...400w的线段树...然后二分查找... ...
- NOJ 1074 Hey Judge(DFS回溯)
Problem 1074: Hey Judge Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit interger IO format: ...
- 【教程】如何正确的写一个Lemon/Cena的SPJ(special judge)
转自:http://www.cnblogs.com/chouti/p/5752819.html Special Judge:当正确的输出结果不唯一的时候需要的自定义校验器 首先有个框架 #includ ...
- 九度 Online Judge 之《剑指 Offer》一书相关题目解答
前段时间准备华为机试,正好之前看了一遍<剑指 Offer>,就在九度 Online Judge 上刷了书中的题目,使用的语言为 C++:只有3题没做,其他的都做了. 正如 Linus To ...
- hdu 3339 In Action 背包+flyod
In Action Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=333 ...
- UVa Online Judge 工具網站
UVa Online Judge 工具網站 UVa中译题uHuntAlgorithmist Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 Mirror UVa Online Judg ...
- [swustoj 1021] Submissions of online judge
Submissions of online judge(1021) 问题描述 An online judge is a system to test programs in programming c ...
- Bzoj 3339: Rmq Problem && Bzoj 3585: mex 莫队,树状数组,二分
3339: Rmq Problem Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 833 Solved: 397[Submit][Status][D ...
随机推荐
- java 自定义注解,并使用示例
场景: 对需要校验 手机验证码和短信验证码的controller方法添加 自定义的注解 @CheckType 1. 定义注解 /** * 需要短信.验证码验证方法上的注解 * date: 2018年 ...
- [转]Android专家级别的面试总结
Android专家级别的面试总结 2017年02月15日 16:56:28 阅读数:1225 1.. 自定义View流程 onMeasure, onLayout, onDraw, 采用深度优先,因为必 ...
- OpenGL 透视投影推导图解
有它足够了,转载自:http://blog.sina.com.cn/s/blog_73428e9a0102v920.html
- css 尺寸、边框、内边距、背景以及css Sprite
上节课回顾: HTML标签: 格式排版 p 段落 双br 换行 单hr 分隔线 单h1~h6 标题 双pre 原样格式化输出 双div 标签,无任何特殊意义 HTML标签 :文本 <em> ...
- 02html基础
02_html 1.几个标签 1.1 meta标签 meta标签的属性有name和http-equiv,其中name属性用于描述网页,对应于content(网页内容). <meta name=& ...
- Android开发精品收藏贴
各种下拉刷新效果: https://github.com/scwang90/SmartRefreshLayout
- [转]qt QTableWidget&&QTableView 导出数据到excel
转自http://blog.csdn.net/fairystepwgl/article/details/54576372 注意:由于在qt导出的过程中分为QTableWidget导出文件到excel和 ...
- cmd命令002
cd..--> 返回上一级目录 cd\ --> 返回根目录"cd /d e:"--> 将当前盘符切换到e盘,"cd users/admin"- ...
- SQL Server数据库的除法默认向下取整,要返回小数的解决方法
num1; / 1000.0 num2; * 1.0 num3; num4; 结果:
- sublime text 3 安装Nodejs插件
如题 1)集成Nodejs插件到sublime,地址:https://github.com/tanepiper/SublimeText-Nodejs2)解压zip文件, 并重命名文件夹“Nodejs” ...