SGU 271 Book Pile
- a book is added to the top of the pile,
- top K books are rotated. If there are less than K books on the table, the whole pile is rotated.
First operation is denoted as ADD(S) where S is the name of the book, and the second operations is denoted as ROTATE.
The maximum number of books is no more than 40000. All book names are non-empty sequences of no more than 3 capital Latin letters. The names of the books can be non-unique.
A
B
ADD(C)
ROTATE
ADD(D)
A
C
B
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
#include <vector>
#include<bitset>
#include<map>
#include<deque>
using namespace std;
typedef long long LL;
const int maxn = 1e5+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
const int inf = 0x3f3f3f3f;
#define lson l,m,2*rt
#define rson m+1,r,2*rt+1 int main(){
// freopen("in.txt","r",stdin);
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
deque<string>q1;
deque<string>q2;
int dir=;
for(int i=;i<n;i++){
char str[];
scanf("%s",str);
if(q1.size()>=k) q2.push_back(string(str));
else q1.push_back(string(str));
}
for(int i=;i<m;i++){
char str[];
scanf("%s",str);
if(str[]=='A'){
string s="";
int len=strlen(str);
int ok=;
for(int j=;j<len;j++){
if(str[j]=='(') ok=;
else if(str[j]==')') ok=;
else if(ok) s+=str[j];
}
if(dir) q1.push_front(s);
else q1.push_back(s); if(q1.size()>k){
if(dir){
q2.push_front(q1.back());
q1.pop_back();
}else{
q2.push_front(q1.front());
q1.pop_front();
}
}
}else dir = !dir;
}
if(dir){
while(!q1.empty()){
cout<<q1.front()<<endl;
q1.pop_front();
}
}else{
while(!q1.empty()){
cout<<q1.back()<<endl;
q1.pop_back();
}
}
while(!q2.empty()){
cout<<q2.front()<<endl;
q2.pop_front();
}
return ;
}
SGU 271 Book Pile的更多相关文章
- SGU 271 Book Pile (双端队列)
题意:n,m,k,表示有一个长度为 n 的序列,有 m 个操作,操作有 2 种,第一种是 ADD 在前面添加一个串,第二种是把前 k 个进行翻转,问你最后的序列是什么样的. 析:很明显,如果直接模拟, ...
- book pile SGU - 271
有n本书从上到下摞在一起,有两种操作.ADD(C)表示把一本新书C放到这一摞书的最顶上,ROTATE表示将前K本书进行反转.在一系列操作后输出最后书的顺序 分析: 当时听别人讲这个题的时候很懵逼,后来 ...
- codeforces#271 (Div. 2)预处理
B. Worms time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
- SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...
- Codeforces Round #271 (Div. 2)题解【ABCDEF】
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
随机推荐
- Install Kernel 3.10 on CentOS 6.5
http://bicofino.io/2014/10/25/install-kernel-3-dot-10-on-centos-6-dot-5/ https://gree2.github.io/lin ...
- Oracle 数据库 Only 导出空表的方法
1. 之前因为oracle11.2.0.1 的bug(deferred_segment_creation) 引起无法将空表导出. 有时给同事解释上半个小时他们也不知道 如何处理 或者是 他们不会用ex ...
- 手动安装ettercap的过程
知乎推送了一个中间人攻击的软件 ettercap 想着尝试进行一下安装学习, 如果有机会的话安全测试部分应该用的到. 1. 下载: wget https://codeload.github.com/E ...
- C/C++的内存泄漏检测工具Valgrind memcheck的使用经历
Linux下的Valgrind真是利器啊(不知道Valgrind的请自觉查看参考文献(1)(2)),帮我找出了不少C++中的内存管理错误,前一阵子还在纠结为什么VS 2013下运行良好的程序到了Lin ...
- rem布局进阶
<script>!function(e){function t(a){if(i[a])return i[a].exports;var n=i[a]={exports:{},id:a,loa ...
- React learn path
React learn path The Road to learn React https://github.com/the-road-to-learn-react https://roadtore ...
- 创建一个规范的django项目
1. 创建项目 2. 创建static目录及配置 1.创建放css, javascript,img的目录 2.在settings.py中将static绝对路径保存到变量STATICFILES_DIRS ...
- C# region指令和控制台清零
region指令 有的时候,为了完成一个需求,可能会写几十行.几百行.甚至几千行代码. 当代码数量非常多的时候,尽管你可以使用很详细的注释来帮助阅读,但也不太容易分清楚哪些代码在干什么事情. 因此,C ...
- ES6定型数组
前面的话 定型数组是一种用于处理数值类型(正如其名,不是所有类型)数据的专用数组,最早是在WebGL中使用的,WebGL是OpenGL ES 2.0的移植版,在Web 页面中通过 <canvas ...
- 13函数式编程&Stream流
13.1常用的函数式接口总结 接口名称 方法名称 抽象/默认 延迟/终结 方法描述 Supplier get 抽象 终结 供给型接口,无参有返回值,主要用于 Consumer accept 抽象 ...