hrbust 训练赛 SUG 347

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hrbust 训练赛 SUG 347相关的知识,希望对你有一定的参考价值。

链接:

http://acm.hrbust.edu.cn/vj/index.php?c=problem-problem&id=31748

题目:

Description


His Royal Highness King of Berland Berl XV was a very wise man and had a very accomplished wife, who was aware of the fact, that prominent and outstanding personalities once having written down their names on the pages of glorious History, remain there forever. His Royal Highness King Berl XV experienced an intrinsic, lost nowadays, deep and sincere sense of respect and trust for his beloved spouse. So he decided to acquire a chronicler of his own. Due to the ambiguous nature of misunderstanding and the crying injustice of history to ambiguity, he decided to leave all his royal responsibilities aside and made up his royal mind to find the chronicler, who will make him famous, depicting all his heroic deeds truthfully and gloriously enough.

The King assembled the greatest minds of his kingdom at the Academic Chroniclers Meeting (ACM), as he named it, and decided to test their might. The task was to build the Smallest Lexicographical Concatenation (SLC) out of the given N strings. SLC of N strings s1,..., sN is the lexicographically smallest their concatenation si1 +... + siN, where i1,..., iN is a permutation of integers from 1 through N. It‘s a great privilege to be a chronicler, so don‘t miss your chance and don‘t screw it up! Make the king choose you!

Input
The first line of the input file contains a single integer N (1 ≤ N ≤ 100) indicating the number of strings. The following N lines contain N strings, one string per line. The length of each string is no more than 100 characters. Each string consists only of lowercase Latin letters. There are no any leading or trailing spaces.

Output
Print the SLC of the given N strings to the output file as a single line.

Sample input
6
it
looks
like
an
easy
problem


Sample output


aneasyitlikelooksproblem

解题思路:

题意:(主要是上文的红色字体)有道翻译:
任务是在给定的N字符串中构建最小的字典拼接(SLC)。

N个字符串的SLC,…,sN 是字典上最小的连接 Si1 +…Sin,  i1,……in是一个从1到n的整数排列,

这是一个很荣幸的编年史作家,所以不要错过你的机会,不要搞砸了!让国王选择你!

解法:  区别 “按字典序排序”  和 “字典序上最小的连接”

        按字典序即顺序 a-z (A-Z)输出

        字典序上最小的连接:比如串 str1 = ‘ab‘ ,str2 = ‘ba‘,则 str1 + str2 = ‘abba’ ,

        而str2 + str1 = ‘baab’,所以第二种要比第一种小

代码:

#include<bits/stdc++.h>
using namespace std;

bool cmp(string str1,string str2)
{
    return str1 + str2 < str2 + str1;
}

int main()
{
    int n;
    scanf("%d",&n);
    string s[105];
    for(int i = 0; i < n; i++)
    {
        cin>>s[i];
    }
    sort(s,s+n,cmp);
    for(int i = 0; i < n; i++)
    {
        cout<<s[i];
    }
    return 0;
}

 

以上是关于hrbust 训练赛 SUG 347的主要内容,如果未能解决你的问题,请参考以下文章

hrbust 训练赛 - - - hdu 1016

hrbust 训练赛

hrbust 训练赛 1987

hrbust 训练赛 1143

HRBUST - 2347 - 递归画图 - vj大一上寒假训练2.11

代码随想录算法训练营第13天 | ● 239. 滑动窗口最大值 ● 347.前 K 个高频元素 ● 总结