题目链接:http://codeforces.com/problemset/problem/632/C

C. The Smallest String Concatenation
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You're given a list of n strings a1, a2, ..., an.
You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.

Given the list of strings, output the lexicographically smallest concatenation.

Input

The first line contains integer n — the number of strings (1 ≤ n ≤ 5·104).

Each of the next n lines contains one string ai (1 ≤ |ai| ≤ 50)
consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.

Output

Print the only string a — the lexicographically smallest string concatenation.

Examples
input
4
abba
abacaba
bcd
er
output
abacabaabbabcder
input
5
x
xx
xxa
xxaa
xxaaa
output
xxaaaxxaaxxaxxx
input
3
c
cb
cba
output
cbacbc

题解:

1.设有两个字符串a和b:求他们最小字典序的组合,那么只有两种情况 : a+b 和 b+a,即取字典序小的那个。

2.字符串个数由两个推广到n个,那么即相当于在原基础上插入新的字符串,使得字典序最小。所以这是一个排序的过程。

代码如下:

 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 5e4+; string s[maxn];
int n; bool cmp(string a, string b)
{
return a+b<b+a;
} int main()
{
cin>>n;
for(int i = ; i<=n; i++)
cin>>s[i]; sort(s+,s++n,cmp);
for(int i = ; i<=n; i++)
cout<<s[i];
cout<<endl;
return ;
}

Educational Codeforces Round 9 C. The Smallest String Concatenation —— 贪心 + 字符串的更多相关文章

  1. Educational Codeforces Round 9 C. The Smallest String Concatenation(字符串排序)

    You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some or ...

  2. Educational Codeforces Round 9 C. The Smallest String Concatenation 排序

    C. The Smallest String Concatenation 题目连接: http://www.codeforces.com/contest/632/problem/C Descripti ...

  3. Educational Codeforces Round 8 C. Bear and String Distance 贪心

    C. Bear and String Distance 题目连接: http://www.codeforces.com/contest/628/problem/C Description Limak ...

  4. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  5. Educational Codeforces Round 16 E. Generate a String dp

    题目链接: http://codeforces.com/problemset/problem/710/E E. Generate a String time limit per test 2 seco ...

  6. Educational Codeforces Round 16 E. Generate a String (DP)

    Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...

  7. Educational Codeforces Round 40 I. Yet Another String Matching Problem

    http://codeforces.com/contest/954/problem/I 给你两个串s,p,求上一个串的长度为|p|的所有子串和p的差距是多少,两个串的差距就是每次把一个字符变成另一个字 ...

  8. Educational Codeforces Round 62 (Rated for Div. 2) C 贪心 + 优先队列 + 反向处理

    https://codeforces.com/contest/1140/problem/C 题意 每首歌有\(t_i\)和\(b_i\)两个值,最多挑选m首歌,使得sum(\(t_i\))*min(\ ...

  9. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

随机推荐

  1. Linux终端颜色设置

    http://blog.sina.com.cn/s/blog_65a8ab5d0101g6cf.html http://www.tuicool.com/articles/NRZfIj #PS1='${ ...

  2. tomcat知识点

    (1)使用线程池   Servlet引擎为每一个请求创建一个隔离的线程,分配这个线程给service()方法,在它执行完后移除这个线程.默认情况下,servlet引擎 为每一个请求创建新的线程.因为创 ...

  3. uitableview执行deleteRowsAtIndexPaths时出错

    Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid updat ...

  4. Code Sign error: a valid provisioning profile matching the application's Identifier 'com. sensoSource.VoiceRecorder' could not be found

    如果不是com. sensoSource.VoiceRecorder,在xxx-info.plist里Bundle identifier里替换成你的证书名 xxx是你的工程名 在Bundle iden ...

  5. Android自定义xml解析

    <?xml version="1.0" encoding="utf-8"?> <resources> <Users> < ...

  6. Neural Networks and Deep Learning学习笔记ch1 - 神经网络

    近期開始看一些深度学习的资料.想学习一下深度学习的基础知识.找到了一个比較好的tutorial,Neural Networks and Deep Learning,认真看完了之后觉得收获还是非常多的. ...

  7. G 全然背包

    <span style="color:#3333ff;">/* /* _________________________________________________ ...

  8. python(38)- 网络编程socket

    一 客户端/服务器架构 即C/S架构,包括 1.硬件C/S架构(打印机) 2.软件C/S架构(web服务) 美好的愿望: 最常用的软件服务器是 Web 服务器.一台机器里放一些网页或 Web 应用程序 ...

  9. 数据迁移实战:基于Kettle的Mysql到DB2的数据迁移

    From:https://my.oschina.net/simpleton/blog/525675 一.什么是ETL ETL,是英文 Extract-Transform-Load 的缩写,用来描述将数 ...

  10. inception安装步骤---自己整理的安装步骤

    inception安装步骤---自己整理的安装步骤2015-09-18 15:51 6185人阅读 评论(1) 收藏 举报 分类: inception相关版权声明:本文为博主原创文章,未经博主允许不得 ...