CF358C.Dima and Containers
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck.
Inna wants her present to show Dima how great a programmer he is. For that, she is going to give Dima commands one by one. There are two types of commands:
- Add a given number into one of containers. For the queue and the stack, you can add elements only to the end. For the deck, you can add elements to the beginning and to the end.
- Extract a number from each of at most three distinct containers. Tell all extracted numbers to Inna and then empty all containers. In the queue container you can extract numbers only from the beginning. In the stack container you can extract numbers only from the end. In the deck number you can extract numbers from the beginning and from the end. You cannot extract numbers from empty containers.
Every time Dima makes a command of the second type, Inna kisses Dima some (possibly zero) number of times. Dima knows Inna perfectly well, he is sure that this number equals the sum of numbers he extracts from containers during this operation.
As we've said before, Dima knows Inna perfectly well and he knows which commands Inna will give to Dima and the order of the commands. Help Dima find the strategy that lets him give as more kisses as possible for his birthday!
迪马的生日快到了!这是个大日子!萨廖日送给迪马的礼物是:萨廖日将不在房间里,不会打扰迪马和因娜庆祝生日。因娜送给迪马的礼物是一个栈(stack)、一个队列(queue)和一个双端队列(deck)。
因娜希望她的礼物能向迪马展示他有多么出色的编程能力。为此,她将逐条向迪马发出指令。指令共有两类:
- 将给定数字插入某个容器中。对于队列和栈,你只能在尾部插入元素;对于双端队列,你既可在头部也可在尾部插入元素。
- 从至多三个互不相同的容器中各提取一个数字。将所有被提取出的数字告诉因娜,然后清空所有这些容器。在队列中,你只能从头部提取数字;在栈中,你只能从尾部提取数字;在双端队列中,你既可从头部也可从尾部提取数字。禁止从空容器中提取数字。
每次迪马执行第二类指令时,因娜都会亲吻迪马若干次(可能为零次)。迪马对因娜非常了解,他确信亲吻次数恰好等于此次操作中从各容器中提取出的所有数字之和。
如前所述,迪马对因娜了如指掌,他知道因娜将向他发出哪些指令以及这些指令的执行顺序。请帮助迪马找到一种策略,使他在生日当天获得尽可能多的亲吻次数!
输入格式
The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer:
- Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers.
- Integer 0 shows that Inna asks Dima to make at most three extractions from different containers.
第一行包含一个整数 n(1≤n≤105)——表示 Inna 发出的命令数量。接下来有 n 行,描述 Inna 的命令。每行包含一个整数:
- 整数 a(1≤a≤105)表示 Inna 命令 Dima 将数字 a 加入某个容器中;
- 整数 0 表示 Inna 要求 Dima 从不同的容器中最多执行三次提取操作。
输出格式
Each command of the input must correspond to one line of the output — Dima's action.
For the command of the first type (adding) print one word that corresponds to Dima's choice:
- pushStack — add to the end of the stack;
- pushQueue — add to the end of the queue;
- pushFront — add to the beginning of the deck;
- pushBack — add to the end of the deck.
For a command of the second type first print an integer k (0 ≤ k ≤ 3), that shows the number of extract operations, then print k words separated by space. The words can be:
- popStack — extract from the end of the stack;
- popQueue — extract from the beginning of the line;
- popFront — extract from the beginning from the deck;
- popBack — extract from the end of the deck.
The printed operations mustn't extract numbers from empty containers. Also, they must extract numbers from distinct containers.
The printed sequence of actions must lead to the maximum number of kisses. If there are multiple sequences of actions leading to the maximum number of kisses, you are allowed to print any of them.
输入中的每条命令必须对应输出中的一行——即迪马的操作。
对于第一类命令(添加操作),输出一个单词,表示迪马的选择:
pushStack— 添加到栈的末尾;pushQueue— 添加到队列的末尾;pushFront— 添加到双端队列的开头;pushBack— 添加到双端队列的末尾。
对于第二类命令(提取操作),首先输出一个整数 k(0 ≤ k ≤ 3),表示执行提取操作的次数,然后在同一行输出 k 个由空格分隔的单词。这些单词可以是:
popStack— 从栈的末尾提取;popQueue— 从队列的开头提取;popFront— 从双端队列的开头提取;popBack— 从双端队列的末尾提取。
所输出的操作不得从空容器中提取数字;此外,所有提取操作必须来自互不相同的容器。
所输出的操作序列必须使得获得的吻数最大化。若存在多个能达到最大吻数的操作序列,任选其一输出即可。
输入输出样例
输入#1
10 0 1 0 1 2 0 1 2 3 0
输出#1
0 pushStack 1 popStack pushStack pushQueue 2 popStack popQueue pushStack pushQueue pushFront 3 popStack popQueue popFront
输入#2
4 1 2 3 0
输出#2
pushStack pushQueue pushFront 3 popStack popQueue popFront
输入解题思路,AI测评打分。不知道怎么写?