#63658. [ USACO 2023 Open Bronze]Moo Language
[ USACO 2023 Open Bronze]Moo Language
暂无测试数据。
英文题面
Farmer John is interested in better interacting with his fellow cows, so he decided he will learn the moo language!
Moo language is actually quite similar to English, but more minimalistic. There are only four types of words: nouns, transitive verbs, intransitive verbs, and conjunctions. Every two consecutive words must be separated by a space. There are also only two types of punctuation: periods and commas. When a period or comma appears after a word, it appears directly after the word, and is then followed by a space if another word appears next.
A sentence needs to follow one of the following formats:
Type 1: noun + intransitive verb.
Type 2: noun + transitive verb + noun(s).
Specifically, at least one noun must follow the transitive verb, and there must be a comma in front of every following noun besides the first following noun.
Two sentences may be joined into a compound sentence if a conjunction is placed in between them. The resulting compound sentence cannot be further joined with other sentences or other compound sentences. Every sentence (or compound sentence, if two sentences are joined) must end with a period.
Farmer John has a word bank of $N$ words, $C$ commas, and $P$ periods $(1≤P,C≤N≤10^3)$. He may only use a word or punctuation mark as many times as it appears in the word bank. Help him output a sequence of sentences containing the maximum possible number of words.
Each input file contains $ (1≤T≤100)$ independent instances of this problem.
译文
约翰农夫有兴趣更好地与他的奶牛同伴互动,因此他决定学习“哞语”!“哞语”实际上与英语非常相似,但更加极简。它只有四种类型的词:名词、及物动词、不及物动词和连词。每两个相邻的词必须用一个空格分隔。标点符号也只有两种类型:句号和逗号。当一个句号或逗号出现在一个词之后时,它会直接出现在该词之后,如果下一个单词出现,则后面跟着一个空格。一个句子需要遵循以下格式之一:
类型 1:名词 + 不及物动词。
类型 2:名词 + 及物动词 + 名词(们)。
具体而言,至少要在及物动词后跟随一个名词,并且在除第一个名词以外的每个随后的名词前必须有逗号。如果在两个句子之间放置连词,则可以将它们组合成复合句。生成的复合句不能进一步与其他句子或其他复合句组合。每个句子(或复合句,如果两个句子被连接)必须以句号结束。约翰农夫有一个词库,其中有 $N$ 个单词、$C$ 个逗号和 $P$ 个句号$(1≤P,C≤N≤10^3)$。他只能使用词库中出现的单词或标点符号。请帮助他输出包含尽可能多单词的句子序列。每个输入文件包含此问题的 $ (1≤T≤100)$ 个独立实例。
输入格式
The first line contains $T$, the number of instances. Each instance is specified as follows:The first line consists of three integers, $N$,$C$, and $P$.
The $N$ following lines will consist of two strings. The first string will be the word itself that FJ can use (a string of at least 1 and at most 10 lowercase letters), and the second string will be either one of the following: noun, transitive-verb, intransitive-verb, or conjunction, denoting the type of the word. It is possible the same word occurs more than once in FJ's word bank, but it will always have the same type each time it appears.
第一行包含 $T$,即实例的数量。每个实例指定如下:
第一行由三个整数 $N$、$C$ 和 $P$ 组成。
接下来 $N$ 行将包含两个字符串。第一个字符串将是农夫约翰可以使用的单词(一个由至少 1 个至多 10 个小写字母组成的字符串),第二个字符串将是以下之一:名词、及物动词、不及物动词或连词,表示单词的类型。可能会在农夫约翰的词库中多次出现相同的单词,但每次出现时它的类型总是相同的。
输出格式
In the first line, output the maximum possible number of words.In the second line, output any sequence of sentences with the maximum possible number of words. Any valid sequence will be accepted.
第一行输出最大可能的单词数量。第二行输出任何具有最大可能单词数量的句子序列。任何有效的序列都将被接受。
数据范围
输入编号 2-6:$N≤10$
输入编号 7-11:$N≤100$
输入编号 12-16:$N≤1000$
当输入编号被 5 整除余数为 2 时:不存在及物动词。
当输入编号被 5 整除余数为 3 时:不存在不及物动词。
当输入编号被 5 整除余数为 4 时:不存在连词。
Inputs 2-6: $N≤10$
Inputs 7-11: $N≤100$
Inputs 12-16: $N≤1000$
Inputs with remainder 2 when divided by 5: There are no transitive verbs.
Inputs with remainder 3 when divided by 5: There are no intransitive verbs.
Inputs with remainder 4 when divided by 5: There are no conjunctions.
3
1 1 1
bessie noun
10 5 4
bessie noun
taught transitive-verb
flew intransitive-verb
elsie noun
farmer noun
john noun
and conjunction
and conjunction
nhoj noun
mooed intransitive-verb
24 5 4
but conjunction
bessie noun
taught transitive-verb
flew intransitive-verb
elsie noun
farmer noun
john noun
and conjunction
and conjunction
nhoj noun
mooed intransitive-verb
bob noun
impressed transitive-verb
cow noun
impressed transitive-verb
leaped intransitive-verb
elsie noun
bella noun
buttercup noun
pushed transitive-verb
mooed intransitive-verb
envy noun
john noun
nhoj noun
0
9
nhoj mooed. farmer taught elsie, bessie and john flew.
23
nhoj mooed. nhoj impressed john, farmer, elsie, bessie and cow impressed bob. bella pushed elsie and buttercup flew. envy mooed but john leaped.