300361: CF69C. Game

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Game

题意翻译

### 题目描述 Kostya 在玩一个游戏,他在游戏内成立了公会,包括他在内,工会有 $k$ 名成员。 游戏内有若干种神器可以收集,其中 $n$ 种基础神器可以直接通过购买获得,另外 $m$ 种高级神器只能通过基础神器合成获得。如果某位玩家获得了足够合成某个高级神器的基础神器,那么它们会自动合成为高级神器,参与合成的基础神器会消失,玩家获得 $1$ 个高级神器。注意每位成员拥有的神器是相互独立的。具体合成规则见输入格式。 作为工会会长,Kostya 知道每一位成员购买基础神器的记录。他想知道目前每位成员拥有的神器情况。 ### 输入格式 第 $1$ 行,$4$ 个整数 $k,n,m,q$,表示成员数量,基础神器种类,高级神器种类,购买神器的记录数量。 第 $2 \sim n+1$ 行,每行 $1$ 个字符串,表示每种基础神器的名字。 第 $n+2 \sim n+m+1$ 行,第 $i(1 \le i \le m)$ 行表示一种高级神器的名字和合成规则,如下: 1. $name_i$。这是一个字符串,表示高级神器的名字。 2. $p_i$。这是一个正整数,表示这个高级神器需要 $p_i$ 种基础神器合成。 3. $art_{i,j}(1 \le j \le p_i)$。这是一个字符串,表示合成需要的第 $j$ 种基础神器的名字。 4. $num_{i,j}(1 \le j \le p_i)$。这是一个正整数,表示合成需要的第 $j$ 种基础神器的数量。 第 $(n+m+2) \sim (n+m+q+1)$ 行,每行表示一条购买记录,包含 $1$ 个正整数 $x$ 和 $1$ 个字符串 $name$,表示第 $x$ 名成员购买了 $1$ 个名字为 $s$ 的基础神器。 ### 输出格式 输出 $k$ 个区域,第 $i(1 \le i \le k)$ 个区域表示第 $i$ 名成员拥有的神器: 首先用 $1$ 行输出成员拥有的神器种类数 $b_i$; 再按名字的字典序输出第 $i$ 名成员拥有的神器。每个神器单独用 $1$ 行输出,先输出神器的名字,再输出神器的数量,中间用空格分隔。 ### 数据范围 对于 $100\%$ 的数据,保证 $1 \le k \le 100$; $1 \le n \le 50$; $0 \le m \le 50$; $1 \le q \le 500$。

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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.

输入输出样例

输入样例 #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

Input

题意翻译

### 题目描述 Kostya 在玩一个游戏,他在游戏内成立了公会,包括他在内,工会有 $k$ 名成员。 游戏内有若干种神器可以收集,其中 $n$ 种基础神器可以直接通过购买获得,另外 $m$ 种高级神器只能通过基础神器合成获得。如果某位玩家获得了足够合成某个高级神器的基础神器,那么它们会自动合成为高级神器,参与合成的基础神器会消失,玩家获得 $1$ 个高级神器。注意每位成员拥有的神器是相互独立的。具体合成规则见输入格式。 作为工会会长,Kostya 知道每一位成员购买基础神器的记录。他想知道目前每位成员拥有的神器情况。 ### 输入格式 第 $1$ 行,$4$ 个整数 $k,n,m,q$,表示成员数量,基础神器种类,高级神器种类,购买神器的记录数量。 第 $2 \sim n+1$ 行,每行 $1$ 个字符串,表示每种基础神器的名字。 第 $n+2 \sim n+m+1$ 行,第 $i(1 \le i \le m)$ 行表示一种高级神器的名字和合成规则,如下: 1. $name_i$。这是一个字符串,表示高级神器的名字。 2. $p_i$。这是一个正整数,表示这个高级神器需要 $p_i$ 种基础神器合成。 3. $art_{i,j}(1 \le j \le p_i)$。这是一个字符串,表示合成需要的第 $j$ 种基础神器的名字。 4. $num_{i,j}(1 \le j \le p_i)$。这是一个正整数,表示合成需要的第 $j$ 种基础神器的数量。 第 $(n+m+2) \sim (n+m+q+1)$ 行,每行表示一条购买记录,包含 $1$ 个正整数 $x$ 和 $1$ 个字符串 $name$,表示第 $x$ 名成员购买了 $1$ 个名字为 $s$ 的基础神器。 ### 输出格式 输出 $k$ 个区域,第 $i(1 \le i \le k)$ 个区域表示第 $i$ 名成员拥有的神器: 首先用 $1$ 行输出成员拥有的神器种类数 $b_i$; 再按名字的字典序输出第 $i$ 名成员拥有的神器。每个神器单独用 $1$ 行输出,先输出神器的名字,再输出神器的数量,中间用空格分隔。 ### 数据范围 对于 $100\%$ 的数据,保证 $1 \le k \le 100$; $1 \le n \le 50$; $0 \le m \le 50$; $1 \le q \le 500$。

加入题单

算法标签: