A2800 | Cow Line S
来源USACO / 2009
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer John(以下简称 FJ)的 $N$ 头奶牛(用 $1 \dots N$ 编号)在直线上排队。一开始,这条线上没有任何奶牛,随着时间的推移,奶牛们会一个接一个地站到队伍的左边或右边。又过了一会儿,某些奶牛会从队伍里离开,去吃自己最喜欢的草料。
FJ 无法跟踪每一头奶牛,于是,他想让你来帮助他。
奶牛以 $1 \dots N$ 的顺序排队,并且离开的奶牛不会再次回来。数据将会给出 $S$($1 \le S \le 100000$) 条指令,各占一行,分两种:
- $A$ 头奶牛加入了队列(还有一个参数,表示从左加入还是从右加入);
- $K$ 头奶牛从左边或者右边离开了队列(还有两个参数,分别表示从左离开还是从右离开和离开多少头奶牛)。
输入的命令一定是可以执行的。
所有的操作结束后,你的程序应该以从左到右的顺序输出这个奶牛队列。数据保证最后的队列不空。
**【输入格式】**
- 第 $1$ 行:单独一个整数 $S$。
- 第 $2 \dots S+1$ 行:第 $i+1$ 行会有一条命令,有以下几种:
-
-
-
-
**【输出格式】**
- 第 $1 \dots ??$ 行:从左到右输出最后的奶牛队列,一个奶牛编号占一行。
**【样例解释】**
以下为输入的命令及对应的队列:
-
-
-
-
-
-
-
-
-
-
FJ 无法跟踪每一头奶牛,于是,他想让你来帮助他。
奶牛以 $1 \dots N$ 的顺序排队,并且离开的奶牛不会再次回来。数据将会给出 $S$($1 \le S \le 100000$) 条指令,各占一行,分两种:
- $A$ 头奶牛加入了队列(还有一个参数,表示从左加入还是从右加入);
- $K$ 头奶牛从左边或者右边离开了队列(还有两个参数,分别表示从左离开还是从右离开和离开多少头奶牛)。
输入的命令一定是可以执行的。
所有的操作结束后,你的程序应该以从左到右的顺序输出这个奶牛队列。数据保证最后的队列不空。
**【输入格式】**
- 第 $1$ 行:单独一个整数 $S$。
- 第 $2 \dots S+1$ 行:第 $i+1$ 行会有一条命令,有以下几种:
-
A L:一头奶牛从队列左边加入;-
A R:一头奶牛从队列右边加入;-
D L K:$K$ 头奶牛从队伍左边离开;-
D R K:$K$ 头奶牛从队伍右边离开。**【输出格式】**
- 第 $1 \dots ??$ 行:从左到右输出最后的奶牛队列,一个奶牛编号占一行。
**【样例解释】**
以下为输入的命令及对应的队列:
-
A L:$1$;-
A L:$2,1$;-
A R:$2,1,3$;-
A L:$4,2,1,3$;-
D R 2:$4,2$;-
A R:$4,2,5$;-
A R:$4,2,5,6$;-
D L 1:$2,5,6$;-
A L:$7,2,5,6$;-
A R(最终序列):$7,2,5,6,8$。输入格式
* Line 1: A single integer: S
* Lines 2..S+1: Line i+1 contains specification i in one of four formats:
* A L -- a cow arrives on the Left of the line
* A R -- a cow arrives on the Right of the line
* D L K -- K cows depart the Left side of the line
* D R K -- K cows depart the Right side of the line
Input lines never request an operation that can not be performed.
After all the input lines have been processed, your program should print the cows in the line in order from left to right. The final line is guaranteed to be non-empty at the end of the input specifications.
* Lines 2..S+1: Line i+1 contains specification i in one of four formats:
* A L -- a cow arrives on the Left of the line
* A R -- a cow arrives on the Right of the line
* D L K -- K cows depart the Left side of the line
* D R K -- K cows depart the Right side of the line
Input lines never request an operation that can not be performed.
After all the input lines have been processed, your program should print the cows in the line in order from left to right. The final line is guaranteed to be non-empty at the end of the input specifications.
输出格式
\* Line 1: A single integer: S
\* Lines 2..S+1: Line i+1 contains specification i in one of four formats:
\* A L -- a cow arrives on the Left of the line
\* A R -- a cow arrives on the Right of the line
\* D L K -- K cows depart the Left side of the line
\* D R K -- K cows depart the Right side of the line
\* Lines 2..S+1: Line i+1 contains specification i in one of four formats:
\* A L -- a cow arrives on the Left of the line
\* A R -- a cow arrives on the Right of the line
\* D L K -- K cows depart the Left side of the line
\* D R K -- K cows depart the Right side of the line
输入输出样例
输入 #1
10 A L A L A R A L D R 2 A R A R D L 1 A L A R
输出 #1
7 2 5 6 8
Input Resulting Cow Line
A L 1
A L 2 1
A R 2 1 3
A L 4 2 1 3
D R 2 4 2
A R 4 2 5
A R 4 2 5 6
D L 1 2 5 6
A L 7 2 5 6
A R 7 2 5 6 8
A L 1
A L 2 1
A R 2 1 3
A L 4 2 1 3
D R 2 4 2
A R 4 2 5
A R 4 2 5 6
D L 1 2 5 6
A L 7 2 5 6
A R 7 2 5 6 8
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?