当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3389:Kennings

题目描述

Kenning is a form of poetic metaphor, popular in ancient scaldic poetry, when a word is replaced by two or more words. For example, “giver of the gold” is a kenning for “warrior”. This substitution is formal, there is no semantic difference between “poor giver of the gold” and “poor warrior”. Kennings may be nested, so since “serpent’s lair” refers to “gold”, “giver of the serpent’s lair” also refers to warrior.

Imagine that you need some long text by 9:00 AM yesterday. Don’t panic, instead create the text plan and a list of kennings, and then expand the plan using the following algorithm. If the plan is long enough then stop — the text is ready. Otherwise simultaneously replace all words in the plan that have kennings with the corresponding kenning bodies and repeat the algorithm again.

输入解释

The first line of the input file contains three integer numbers: the width of the resulting text w (1 ≤ w ≤ 255), the minimal number of non-whitespace symbols in the resulting text l (1 ≤ l3 000), and the kennings list length n (1 ≤ n ≤ 380). The kenning list follows, a kenning per line. Each line contains the kenning referent followed by the kenning body. The text plan ends the file.

Each kenning body contains at least two words. Kennings may be recursive, like in replacing “GNU” with “GNU is Not UNIX”. The kenning referents are case and grammatical form sensitive, so words “warrior”, “Warrior” and “warriors” are different and may be referred by different kennings. The input file is not longer than 3 000 bytes, and contains only English letters, underscores, spaces, line feeds and digits (in the first line only). There are no two kennings with equal referents. All words have w symbols at most. Adjacent words are separated by exactly one space or line feed. No line has leading or trailing spaces.

输出解释

If the algorithm doesn’t terminate, output just words “No result” in the only output line. Otherwise output the algorithm result, a text with at most w characters (including spaces) per line. All line feeds from the original plan must be preserved, line feed must be inserted before a word if the word does not fit into the previous line. Adjacent words in a line must be separated by exactly one space. The lines must not have leading or trailing spaces. Correct output file will not be longer than 10 000 bytes.

输入样例
21 103 7
king hosts leader
vessel windless bay of horns
horns bulls spears
spears war needles
Sudden Fate catched
death_of doomed to death
Death It was the end
Sudden
death_of Fjolner
in the house of Frodi
Death
of the king
in the vessel
输出样例
Fate catched
doomed to death
Fjolner
in the house of Frodi
It was the end
of the hosts leader
in the windless bay
of bulls spears

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3389

最后修改于 2020-10-29T07:00:24+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000 65536