Description
A word ring is a sequence of words where the last two letters of each word are the same as the first two letters of the next word (and the last two letters of the last word are the same as the first two letters of the first word). For example, the following sequence is a word ring:
intercommunicational
alkylbenzenesulfonate
tetraiodophenolphthalein
Your task is to write a program that, given a list of words, finds a word ring. You have to make the word ring as impressive as possible: the average length of the words in the ring has to be as large as possible. In the above example, the average length is (20 + 21 + 24)/3 ≈ 21.6666 , which makes it somewhat impressive. Note that each word can be used at most once in the ring, and the ring can consist of a single word.
intercommunicational
alkylbenzenesulfonate
tetraiodophenolphthalein
Your task is to write a program that, given a list of words, finds a word ring. You have to make the word ring as impressive as possible: the average length of the words in the ring has to be as large as possible. In the above example, the average length is (20 + 21 + 24)/3 ≈ 21.6666 , which makes it somewhat impressive. Note that each word can be used at most once in the ring, and the ring can consist of a single word.
Input
The input contains several blocks of test c

该博客讨论了一道ACM题目,涉及字符串接龙和平均值优化问题。通过将字符串转化为边和点的形式,寻找环状路径使得平均边权重最大化。通过G++与C++的运行对比,提出利用SPFA算法优化和二分查找策略来解决问题。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



