C. The Smallest String Concatenation-C++sort排序~~
3 seconds
256 megabytes
standard input
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.
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.
Print the only string a — the lexicographically smallest string concatenation.
4
abba
abacaba
bcd
er
abacabaabbabcder
5
x
xx
xxa
xxaa
xxaaa
xxaaaxxaaxxaxxx
3
c
cb
cba
cbacbc
题目意思不难懂,但对于我这种大一菜鸟..........任意连接在一起要求字典序最小,数据50000,一般肯定会超时,但在比赛的时候不知道怎么比较字典序,望而生畏,看题解,我去,快要崩溃了,整个人都不好了...
在这里,有个小技巧,以前确实不知道,今天问学长才知道在C++中,用string定义的字符串直接相加”+“就是连接在一起;
下面来看简短代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=50000+10;
string s[N];
int cmp(string a,string b)
{
return a+b<b+a;//c++中string定义的字符串直接相加表示连接;用char定义还需要用strcat()连接;
}
int main()
{
int n,i;
while(cin>>n)
{
for(i=0;i<n;i++)
cin>>s[i];
sort(s,s+n,cmp);//万万没想到这样就将字典序最小的连接方式找出来了;
for(i=0;i<n;i++)
cout<<s[i];
cout<<endl;
}
return 0;
}
C. The Smallest String Concatenation-C++sort排序~~的更多相关文章
- 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 ...
- CodeForces 632C The Smallest String Concatenation//用string和sort就好了&&string的基础用法
Description You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them togethe ...
- codeforces 632C C. The Smallest String Concatenation(sort)
C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...
- Educational Codeforces Round 9 C. The Smallest String Concatenation 排序
C. The Smallest String Concatenation 题目连接: http://www.codeforces.com/contest/632/problem/C Descripti ...
- C. The Smallest String Concatenation
C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...
- Educational Codeforces Round 9 C. The Smallest String Concatenation —— 贪心 + 字符串
题目链接:http://codeforces.com/problemset/problem/632/C C. The Smallest String Concatenation time limit ...
- codeforces 632C The Smallest String Concatenation
The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...
- codeforces 632C. The Smallest String Concatenation 排序
题目链接 给出n个字符串, 将他们连在一起, 求连玩之后字典序最小的那种情况. 按a+b<b+a排序.... #include <iostream> #include <vec ...
- SPOJ:Lexicographically Smallest(并查集&排序)
Taplu and Abhishar loved playing scrabble. One day they thought of inventing a new game using alphab ...
随机推荐
- saltstack学习笔记--grains基本操作
查看当前已经定义的监控项: [root@master ~]# salt "192.168.75.135" grains.items 192.168.75.135: ---- ...
- 机器学习概念之特征选择(Feature selection)之VectorSlicer算法介绍
不多说,直接上干货! VectorSlicer 算法介绍: VectorSlicer是一个转换器,输入特征向量,输出原始特征向量子集.VectorSlicer接收带有特定索引的向量列,通过对这些索引的 ...
- P1789 【Mc生存】插火把
题目背景 初一党应该都知道...... 题目描述 话说有一天linyorson在Mc开了一个超平坦世界,他把这个世界看成一个n*n的方阵,现在他有m个火把和k个萤石,分别放在x1,y1...xm,ym ...
- 基于ABP的Easyui admin framework正式开放源代码
下载&反馈:http://www.webplus.org.cn v1.0 (2016/9/21) EF6+MVC5+API2+Easyui1.4.2开发 后台管理不使用iframe,全ajax ...
- spring boot 的redis 之初理解
项目到末尾了快, 这几天安排我结合业务场景给项目加上redis 缓存, 我接到这个任务也是懵逼了一会儿: 问了一句让我自己先想办法,没办法硬着头皮查吧, 要不不得不说spring boot 还是好用, ...
- 从URL输入到页面展示都发生了什么?
总的来说分为以下过程: DNS解析 TCP三次握手 发送HTTP请求 服务器端处理请求并返回HTTP保文 浏览器渲染页面 断开连接:TCP的四次挥手 URL到底是什么? URL(Uniform Res ...
- Hadoop分布式集群安装
环境准备 操作系统使用ubuntu-16.04.2 64位 JDK使用jdk1.8 Hadoop使用Hadoop 2.8版本 镜像下载 操作系统 操作系统使用ubun ...
- 世平信息(W 笔试)
选择题 大题 1.启动Thread的方法有几种 算法题 1.写出冒泡排序算法
- Vsphere中ESXi主机ssh开启的三种方法
ESXi 5.5是直接安装在物理主机上的一个虚拟机系统,本质上是一个Linux系统. 平时可以通过VMware Client端或者VMware vCenter进行管理,但对于一些特殊的VMware命令 ...
- CAD交互绘制圆弧(网页版)
在CAD设计时,需要绘制圆弧,用户可以在图面点圆弧起点,圆弧上的一点和圆弧的终点,这样就绘制出圆弧. 主要用到函数说明: _DMxDrawX::DrawArc2 由圆弧上的三点绘制一个圆弧.详细说明如 ...