codeforces 632C. The Smallest String Concatenation 排序

题目链接

给出n个字符串, 将他们连在一起, 求连玩之后字典序最小的那种情况。

按a+b<b+a排序....

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9+7;
const int inf = 1061109567;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
string s[50005];
bool cmp(string a, string b) {
    return a+b<b+a;
}
int main()
{
    int n;
    cin>>n;
    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];
    cout<<endl;
    return 0;
}
时间: 2025-01-20 01:53:13

codeforces 632C. The Smallest String Concatenation 排序的相关文章

CodeForces 632C The Smallest String Concatenation//用string和sort就好了&amp;&amp;string的基础用法

Description 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 c

CodeForces 632C - C. The Smallest String Concatenation

题意: n 个 串,把他们按照某个次序连起来 , 使连接后的字符串字典序最小. 做这题的时候我简直是蠢死了..... #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> using namespace std; const int maxn = 50010; string str[maxn]; bool cmp(str

Educational Codeforces Round 25 F. String Compression(kmp+dp)

题目链接:Educational Codeforces Round 25 F. String Compression 题意: 给你一个字符串,让你压缩,问压缩后最小的长度是多少. 压缩的形式为x(...)x(...)  x表示(...)这个出现的次数. 题解: 考虑dp[i]表示前i个字符压缩后的最小长度. 转移方程解释看代码,这里要用到kmp来找最小的循环节. 当然还有一种找循环节的方式就是预处理lcp,然后通过枚举循环节的方式. 这里我用的kmp找的循环节.复杂度严格n2. 1 #inclu

Codeforces 439D Devu and his Brother(排序)

题目链接:Codeforces 439D  Devu and his Brother 题目大意:Devu和他的哥哥互相深爱着对方,我确信他们是搞基的,为此我还去查了一下Devu是男人名还是女人名,但是后来发现His Brother,所以可以证明,他们就是搞基的.题目很简单,父亲给了他们两个人分别一个数组.但是Devu希望自己最小的数都可以不必哥哥最大的数小,现在对数组中的数有两种操作,一种是加1,一种是减1,问最少进行几次操作可以使得两个数组满足要求. 解题思路:将两个数组合并在一起,然后排序,

Codeforces 56D Changing a String 编辑距离 dp

题目链接:点击打开链接 编辑距离,,== 一边dp一边记录前驱太累,,还是dp后找路径大法好 #include<iostream> #include<cstdio> #include<vector> #include<string.h> using namespace std; #define ll int #define N 1010 char s[N], t[N]; int dp[N][N], n, m; // 0为插入 1为删除 2 3为替换 stru

LC 988. Smallest String Starting From Leaf

Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to 'z': a value of 0 represents 'a', a value of 1represents 'b', and so on. Find the lexicographically smallest string that starts at a leaf of this tree

[LeetCode 988] Smallest String Starting From Leaf

Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to 'z': a value of 0 represents 'a', a value of 1 represents 'b', and so on. Find the lexicographically smallest string that starts at a leaf of this tre

【leetcode】988. Smallest String Starting From Leaf

题目如下: Given the root of a binary tree, each node has a value from 0 to 25representing the letters 'a' to 'z': a value of 0 represents 'a', a value of 1 represents 'b', and so on. Find the lexicographically smallest string that starts at a leaf of thi

【CodeForces 990C】 Bracket Sequences Concatenation Problem

题目链接 luogu &  CodeForces 题目描述 A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting charact