CF69C.Game
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats glued to the game. A few days ago Kostya bought a new RPG game "HaresButtle", which differs from all other games in this genre. It has a huge number of artifacts. As we know, artifacts are divided into basic and composite ones. Only the basic artifacts are available on sale. More powerful composite artifacts are collected from some number of basic artifacts.
After the composing composite artifact, all the components disappear.
Kostya is the head of the alliance, so he has to remember, what artifacts has not only himself, but also his allies. You must identify by sequence of artifacts purchased by Kostya and his allies, how many and which artifacts has been collected by each of them. It is believed that initially no one has any artifacts.
在瓦夏所在的学校里,有一位名叫科斯佳的学生。科斯佳不喜欢物理,而喜欢各种在线游戏。每天放学回家后,科斯佳都会把书包扔到最远的角落,然后坐到他心爱的电脑前。科斯佳甚至边打游戏边吃饭。几天前,科斯佳购买了一款全新的角色扮演游戏《野兔大战》(HaresButtle),这款游戏在同类游戏中独树一帜:它拥有海量的道具。众所周知,道具分为基础道具和合成道具两类。只有基础道具可以在商店中直接购买;更强大的合成道具则需由若干基础道具合成而成。
合成一个合成道具后,所有参与合成的基础道具均会消失。
科斯佳是联盟的首领,因此他不仅要记住自己拥有的道具,还要记住其盟友所拥有的道具。你需要根据科斯佳及其盟友购买道具的序列,确定每个人最终收集到了多少种、哪些道具。初始时,所有人手中均没有任何道具。
输入格式
The first line has 4 natural numbers: k (1 ≤ k ≤ 100) — the number of Kostya's allies, n (1 ≤ n ≤ 50) — the number of basic artifacts, m (0 ≤ m ≤ 50) — the number of composite artifacts, q (1 ≤ q ≤ 500) — the number of his friends' purchases. The following n lines contain the names of basic artifacts. After them m lines contain the descriptions of composite artifacts in the following format:
<Art. Name>: <Art. №1> <Art. №1 Number>, <Art. №2> <Art. №2 Number>, ... <Art. №X> <Art. №Х Number>
All the numbers are natural numbers not exceeding 100 (1 ≤ X ≤ n).
The names of all artifacts are different, they are composed of lowercase Latin letters, and the length of each name is from 1 to 100 characters inclusive. All the words in the format of the description of a composite artifact are separated by exactly one space. It is guaranteed that all components of the new artifact are different and have already been met in the input data as the names of basic artifacts.
Next, each of the following q lines is characterized by the number a__i, the number of a friend who has bought the artifact (1 ≤ a__i ≤ k), and the name of the purchased basic artifact. Let's assume that the backpacks of the heroes are infinitely large and any artifact bought later can fit in there.
It is guaranteed that after the i-th purchase no more than one opportunity to collect the composite artifact appears. If such an opportunity arose, the hero must take advantage of it.
第一行包含 4 个自然数:k(1 ≤ k ≤ 100)——科斯佳的盟友人数,n(1 ≤ n ≤ 50)——基础道具数量,m(0 ≤ m ≤ 50)——合成道具数量,q(1 ≤ q ≤ 500)——他的朋友们的购买次数。接下来的 n 行包含基础道具的名称。随后的 m 行按如下格式给出合成道具的描述:
<道具名称>: <道具编号1> <道具编号1 数量>, <道具编号2> <道具编号2 数量>, ... <道具编号X> <道具编号X 数量>
所有数字均为不超过 100 的自然数(1 ≤ X ≤ n)。
所有道具名称互不相同,均由小写拉丁字母组成,且每个名称长度为 1 至 100 个字符(含端点)。合成道具描述格式中的所有单词均以恰好一个空格分隔。保证新道具的所有组件互不相同,且均已作为基础道具名称在输入数据中出现过。
接下来的 q 行中,每行描述一次购买:首先是数字 a__i,表示购买该道具的朋友编号(1 ≤ a__i ≤ k),其次是所购基础道具的名称。假设英雄们的背包容量无限大,因此之后购买的任何道具均可放入其中。
保证在第 i 次购买后,至多出现一次合成合成道具的机会。若该机会出现,则英雄必须立即执行合成。
输出格式
The output file should consist of k blocks. The first line should contain number b__i — the number of different artifacts the i-th ally has. Then the block should contain b__i lines with the names of these artifacts and the number of these artifacts. At that the lines should be printed in accordance with the lexicographical order of the names of the artifacts. In each block all the artifacts must be different, and all the numbers except the b__i should be positive.
输出文件应包含 k 个块。每个块的第一行应包含数字 b__i —— 表示第 i 个盟友所拥有的不同遗物的数量。随后该块应包含 b__i 行,每行包含一个遗物的名称及其数量。这些行应按照遗物名称的字典序排列。在每个块中,所有遗物必须互不相同,且除 b__i 外的所有数字均须为正数。
输入输出样例
输入#1
2 3 2 5 desolator refresher perseverance vanguard: desolator 1, refresher 1 maelstorm: perseverance 2 1 desolator 2 perseverance 1 refresher 2 desolator 2 perseverance
输出#1
1 vanguard 1 2 desolator 1 maelstorm 1
输入解题思路,AI测评打分。不知道怎么写?