CF120G.Boom

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let's consider the famous game called Boom (aka Hat) with simplified rules.

There are n teams playing the game. Each team has two players. The purpose of the game is to explain the words to the teammate without using any words that contain the same root or that sound similarly.

Player j from team i (1 ≤ i ≤ n, 1 ≤ j ≤ 2) is characterized by two numbers: a__ij and b__ij. The numbers correspondingly represent the skill of explaining and the skill of understanding this particular player has.

Besides, m cards are used for the game. Each card has a word written on it. The card number k (1 ≤ k ≤ m) is characterized by number c__k — the complexity of the word it contains.

Before the game starts the cards are put in a deck and shuffled. Then the teams play in turns like that: the 1-st player of the 1-st team, the 1-st player of the 2-nd team, ... , the 1-st player of the n-th team, the 2-nd player of the 1-st team, ... , the 2-nd player of the n-th team, the 1-st player of the 1-st team and so on.

Each turn continues for t seconds. It goes like that: Initially the time for each turn is t. While the time left to a player is more than 0, a player takes a card from the top of the deck and starts explaining the word it has to his teammate. The time needed for the j-th player of the i-th team to explain the word from the card k to his teammate (the q-th player of the i-th team) equals max(1, c__k - (a__ij + b__iq) - d__ik) (if j = 1,  then q = 2,  else q = 1). The value d__ik is the number of seconds the i-th team has already spent explaining the word k during the previous turns. Initially, all d__ik equal 0. If a team manages to guess the word before the end of the turn, then the time given above is substracted from the duration of the turn, the card containing the guessed word leaves the game, the team wins one point and the game continues. If the team doesn't manage to guess the word, then the card is put at the bottom of the deck, d__ik increases on the amount of time of the turn, spent on explaining the word. Thus, when this team gets the very same word, they start explaining it not from the beginning, but from the point where they stopped. The game ends when words from all m cards are guessed correctly.

You are given n teams and a deck of m cards. You should determine for each team, how many points it will have by the end of the game and which words the team will have guessed.

我们来考虑一个著名的游戏——“爆炸”(又称“帽子”),其规则经过简化。

共有 nn 支队伍参与该游戏。每支队伍由两名玩家组成。游戏的目标是向自己的队友解释某个词语,但不得使用任何与该词具有相同词根或发音相似的词语。

第 ii 支队伍(1≤i≤n1 \le i \le n)中的第 jj 名玩家(1≤j≤21 \le j \le 2)由两个数值刻画:aija_{ij} 和 bijb_{ij}。这两个数值分别表示该玩家的解释能力和理解能力。

此外,游戏中共使用 mm 张卡片,每张卡片上写有一个单词。第 kk 张卡片(1≤k≤m1 \le k \le m)由一个数值 ckc_k 刻画——即其所含单词的复杂度。

游戏开始前,所有卡片被放入牌堆并洗匀。随后各队按如下顺序轮流进行游戏:第 1 支队伍的第 1 名玩家、第 2 支队伍的第 1 名玩家、……、第 nn 支队伍的第 1 名玩家;接着是第 1 支队伍的第 2 名玩家、……、第 nn 支队伍的第 2 名玩家;然后再次回到第 1 支队伍的第 1 名玩家,依此类推。

每一轮持续 tt 秒。具体流程如下:每轮初始时间为 tt 秒。只要某玩家本轮剩余时间大于 0,他便从牌堆顶部抽取一张卡片,并立即向自己的队友解释该卡片上的单词。第 ii 支队伍的第 jj 名玩家向其队友(即第 ii 支队伍的第 qq 名玩家)解释第 kk 张卡片上单词所需的时间为

max⁡(1, ck−(aij+biq)−dik),\max(1,\, c_k - (a_{ij} + b_{iq}) - d_{ik}),

其中若 j=1j = 1,则 q=2q = 2;若 j=2j = 2,则 q=1q = 1。而 dikd_{ik} 表示在之前的所有轮次中,第 ii 支队伍为解释第 kk 张卡片上的单词已累计花费的秒数。初始时,所有 dik=0d_{ik} = 0。

若某支队伍在本轮结束前成功猜出该单词,则上述计算所得时间将从本轮剩余时间中扣除;该卡片退出游戏;该队伍获得 1 分;游戏继续进行。若该队伍未能在本轮内猜出单词,则该卡片被放至牌堆底部,且 dikd_{ik} 增加一个值——即本轮中用于解释该单词所实际消耗的时间。因此,当该队伍之后再次抽到同一张卡片时,并非从头开始解释,而是从上次中断处继续。

当全部 mm 张卡片上的单词均被正确猜出时,游戏结束。

现给定 nn 支队伍及包含 mm 张卡片的牌堆,请你确定:游戏结束时,每支队伍各获得多少分,以及每支队伍各自猜出了哪些单词。

输入格式

The first line contains two integers n, t (1 ≤ n, t ≤ 100), which correspondingly denote the number of teams and a turn's duration.

Next n lines of the input file contain four integers each: _a__i_1, _b__i_1, _a__i_2, _b__i_2 (1 ≤ a__ij, b__ij ≤ 100) — the skills of the first and the second player of the i-th team. The teams are given in the order in which they play.

The next line of the input file contains integer m (1 ≤ m ≤ 100) the number of cards.

Next 2_m_ lines contain the cards' descriptions. Two lines describe each card. The first line of the description contains the word that consists of no more than 20 characters. The words only contain small Latin letters. The second line of the description contains an integer c__k (1 ≤ c__k ≤ 100) — the complexity of the word written on the k-th card. The cards are listed in the order in which the lie in the deck from top to bottom. The words on all cards are different.

第一行包含两个整数 nn 和 tt(1≤n,t≤1001 \leq n, t \leq 100),分别表示队伍数量和每轮的持续时间。

接下来的 nn 行,每行包含四个整数:ai1, bi1, ai2, bi2a_{i1},\ b_{i1},\ a_{i2},\ b_{i2}(1≤aij, bij≤1001 \leq a_{ij},\ b_{ij} \leq 100)——表示第 ii 支队伍中第一名与第二名选手的技能值。各支队伍按其比赛顺序给出。

输入文件的下一行包含一个整数 mm(1≤m≤1001 \leq m \leq 100),表示卡片的数量。

接下来的 2m2m 行描述这些卡片。每张卡片由两行描述:第一行是一个长度不超过 20 个字符的单词,该单词仅由小写拉丁字母组成;第二行是一个整数 ckc_k(1≤ck≤1001 \leq c_k \leq 100),表示第 kk 张卡片上所写单词的难度。卡片按其在牌堆中从顶到底的顺序列出。所有卡片上的单词互不相同。

输出格式

Print n lines. On the i-th line first print number s__i the number of points the i-th team wins. Then print s__i space-separated words — the words from the cards guessed by team i in the order in which they were guessed.

输出 n 行。在第 i 行,首先输出数字 s__i(即第 i 支队伍获得的分数),然后输出 s__i 个以空格分隔的单词——这些单词是第 i 支队伍猜中的卡片上的单词,按其被猜中的顺序排列。

输入输出样例

  • 输入#1

    2 2
    1 1 1 1
    1 1 1 1
    3
    home
    1
    car
    1
    brother
    1

    输出#1

    2 home car 
    1 brother
  • 输入#2

    2 4
    1 2 2 1
    2 3 2 2
    4
    armchair
    3
    quetzalcoatl
    10
    pilotage
    5
    defibrillator
    7

    输出#2

    2 armchair quetzalcoatl 
    2 pilotage defibrillator

输入解题思路,AI测评打分。不知道怎么写?

首页