题目链接: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. 快速上手 Echarts

    最近使用到了 百度的 Echarts 数据可视化工具,这里简单介绍如何快速上手. 一.下载 这里选择目前最新版本,4.2.1 地址:https://github.com/apache/incubato ...

  2. POJ 2253 Frogger Floyd

    原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  3. java三角形和菱形的打印

    一.三角形的打印 package 向家康; import java.util.Scanner; public class Main { public void san(int num) { for(i ...

  4. link2005 重复定义错误

    造成LNK2005错误主要有以下几种情况:  1.重复定义全局变量. 对于一些初学编程的程序员,有时候会以为需要使用全局变量的地方就可以使用定义申明一下.其实这是错误的,全局变量是针对整个工程的. 正 ...

  5. ios 使用 resignFirstResponder 无法hide键盘

    - (BOOL)disablesAutomaticKeyboardDismissal {    return NO;}

  6. 【sublime text 3】sublime text 3 汉化

    快捷键:Ctrl+Alt+P 输入快捷键Ctrl+Shift+P 在出现的文本框中输入Install Package(或直接输入“ip”)选中packageControl:Install Packag ...

  7. mac os+selenium2+chrome驱动+python3

    mac os 10.11.5 mac自带python2.7,自己下载了python3.5,pip list查看系统中的安装包,本人电脑中已经安装了pip和setuptools,若未安装,请先使用 su ...

  8. [Javascript] Await a JavaScript Promise in an async Function with the await Operator

    The await operator is used to wait for a promise to settle. It pauses the execution of an async func ...

  9. c++程序猿经典面试题(2)

    1.以下程序的输出结果是? #include<stdio.h> main(){ int b=3; int arr[]={6,7,8,9,10}; int *ptr=arr; *(ptr++ ...

  10. [学习笔记]Java异常机制

    概述 异常 程序在执行时出现的不正常情况,是对问题的描写叙述.将问题进行对象的封装. Java中的异常,就是对不正常情况进行描写叙述后的对象体现. 异常体系 Throwable     |--Erro ...