文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition) (优先队列)...

题目链接:http://abc042.contest.atcoder.jp/tasks/abc042_b

Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Iroha has a sequence of N strings S1,S2,…,SN. The length of each string is L.

She will concatenate all of the strings in some order, to produce a long string.

Among all strings that she can produce in this way, find the lexicographically smallest one.

Here, a string s=s1s2s3...sn is lexicographically smaller than another string t=t1t2t3...tm if and only if one of the following holds:

  • There exists an index i(1≦imin(n,m)), such that sj=tj for all indices j(1≦j<i), and si<ti.
  • si=ti for all integers i(1≦imin(n,m)), and n<m.

 

Constraints

  • 1≦N,L≦100
  • For each i, the length of Si equals L.
  • For each iSi consists of lowercase letters.

Input

The input is given from Standard Input in the following format:

N L
S1
S2
:
SN

Output

Print the lexicographically smallest string that Iroha can produce.


Sample Input 1

Copy
3 3
dxx
axx
cxx

Sample Output 1

Copy
axxcxxdxx

The following order should be used: axxcxxdxx.

题解:大致意思是是对字符串排序然后顺序输出 尝试用了下字符串的优先队列 以为会哇一发 没想到居然过了 

   可是我用优先队列之后 感觉 L 这个数据就废了啊 也没看其他的做法 不知道有没有用它 

 1 #include 
 2 #include 
 3 #include 
 4 #include 
 5 #include 
 6 #include 
 7 #include 
 8 #include 
 9 #include 
10 #include 
11 #include <set>
12 #include 
13 using namespace std;
14 #define lowbit(x) (x&(-x))
15 #define max(x,y) (x>y?x:y)
16 #define min(x,y) (x17 #define MAX 100000000000000000
18 #define MOD 1000000007
19 #define pi acos(-1.0)
20 #define ei exp(1)
21 #define PI 3.141592653589793238462
22 #define INF 0x3f3f3f3f3f
23 #define mem(a) (memset(a,0,sizeof(a)))
24 typedef long long ll;
25 ll gcd(ll a,ll b){
26     return b?gcd(b,a%b):a;
27 }
28 bool cmp(int x,int y)
29 {
30     return x>y;
31 }
32 const int N=10005;
33 const int mod=1e9+7;
34 int main()
35 {
36     std::ios::sync_with_stdio(false);
37     int n,l;
38     cin>>n>>l;
39     string a;
40     priority_queue<string,vector<string>,greater<string> >q;
41     for(int i=0;i){
42         cin>>a;
43         q.push(a);
44     }
45     while(q.size()>0){
46         string b=q.top();
47         cout<<b;
48         q.pop();
49     }
50     cout<<endl;
51     return 0;
52 }

转载于:https://www.cnblogs.com/shixinzei/p/7287058.html

你可能感兴趣的:(文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition) (优先队列)...)