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(string a, string b)
{
    if((a+b) < (b+a)) return true;
    return false ;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>str[i];
    }
    sort(str,str+n,cmp);
    for(int i=0;i<n;i++){
        cout<<str[i];
    }
    return 0;
}
时间: 2024-12-25 06:45:36

CodeForces 632C - C. 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. 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> #inclu

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 710 E. Generate a String (dp)

题目链接:http://codeforces.com/problemset/problem/710/E 加或者减一个字符代价为x,字符数量翻倍代价为y,初始空字符,问你到n个字符的最小代价是多少. dp[i]表示i个字符的最小代价. 当i为偶数个的时候,由+1或者*2得到. 当i为奇数个的时候,由+1或者*2-1得到. 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <algorithm&

CodeForces 632C Grandma Laura and Apples (模拟)

题意:有n个人买苹果,当苹果剩余偶数时买走一半,当苹果剩余奇数时,先买走一半,再用半价买走一个苹果,最终苹果恰好卖完.农民收入为多少. 析:反向模拟. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include &l

CodeForces - 963D:Frequency of String (bitset暴力搞)

You are given a string ss. You should answer nn queries. The ii-th query consists of integer kiki and string mimi. The answer for this query is the minimum length of such a string tt that tt is a substring of ss and mimi has at least kiki occurrences

【CodeForces 624C】Graph and String

题 题意 n个表示abc三个字符的点,a和b是相连的,b和c是相连的,相同的是相连的,现在给你n个点和他们之间的m条边,判断是否存在这样的字符串,存在则给出一个符合条件的. 分析 我的做法是找出所有的b,因为b是只和自己没有连接,所以有n-1个连线,然后找出第一个不是b的,然后所有和该点没有连线的都设置为c,有连线而不是b的就设置为a,然后再把该点设置为a. 接下来,根据题目条件,判断一下我设置出来的字符串成不成立.就是如果不相连接却是相同字母或者有b字母,还有如果相连接却是a和c,那都是不符合