Educational Codeforces Round 54 (Rated for Div. 2) A. Minimizing the String

贪心

因字典序位越靠前权越大 

从初始位置枚举此位后一位向后与原串比较字典序

若小则为最优

输出结束

/*
    Zeolim - An AC a day keeps the bug away
*/

//pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <sstream>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;

const int MAXN = 1e6 + 10;

char arr[MAXN];

int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);     cout.tie(0);
    //freopen("D://test.in", "r", stdin);
    //freopen("D://test.out", "w", stdout);
    
    int n;

    scanf("%d%s", &n, arr);

    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n + 1; j++)
        {
            if(arr[j] < arr[i])
            {
                for(int k = 0; k < n; k++)
                {
                    if(k != i)
                        printf("%c", arr[k]);
                }
                goto l1;
            }
            else
            {
                break;
            }
        }
    }
    
    l1:

    printf("
");

    return 0;
}
原文地址:https://www.cnblogs.com/zeolim/p/12270415.html