zoukankan      html  css  js  c++  java
  • Lexicography

    Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it.

    At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words and minimize one of them. This was much harder!

    Formally, Lucy wants to make nn words of length ll each out of the given nln⋅l letters, so that the kk-th of them in the lexicographic order is lexicographically as small as possible.

    Input

    The first line contains three integers nn, ll, and kk (1≤kn≤10001≤k≤n≤1000; 1≤l≤10001≤l≤1000) — the total number of words, the length of each word, and the index of the word Lucy wants to minimize.

    The next line contains a string of nln⋅l lowercase letters of the English alphabet.

    Output

    Output nn words of ll letters each, one per line, using the letters from the input. Words must be sorted in the lexicographic order, and the kk-th of them must be lexicographically as small as possible. If there are multiple answers with the smallest kk-th word, output any of them.

    Examples

    Input

    Copy

    3 2 2
    abcdef
    

    Output

    Copy

    af
    bc
    ed
    

    Input

    Copy

    2 3 1
    abcabc
    

    Output

    Copy

    aab
    bcc
    
    //借鉴
    #include<bits/stdc++.h>
    using namespace std;
    string sp[1005];
    bool flag[1005];
    int main()
    {
       memset(flag,false,sizeof(flag));
        multiset<string>st;
        int n,m,k;
        cin>>n>>m>>k;
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        int pos=0;
        while(sp[k].size()<m)
        {
            for(int i=1;i<=k;i++)
            {
                if(flag[i])
                {
                    sp[i].push_back(s.back());
                    s.pop_back();
                    pos--;
                }
                else
                    sp[i].push_back(s[pos]);
                pos++;
            }
            for(int j=1;j<k;j++)
            {
                if(!flag[j]&&sp[j].back()!=sp[k].back()) flag[j]=true;
            }
        }
        for(int i=1;i<=n-k;i++)
        {
            st.insert(s.substr(pos,m));
            pos+=m;
        }
        for(int i=1;i<=k;i++)
            st.insert(sp[i]);
        for(auto R : st)
            cout<<R<<endl;
        return 0;
     
    }
    
  • 相关阅读:
    LoadRunner字符编码转换
    登山记02-百丈岭古道(昌北古道)_20201213
    JVM GC原理和监控
    登山记01_径山古道_20201107
    awk命令
    shell计算文件中某一列的平均值
    linux命令后台运行
    二维数组_基础(九)
    一维数组(八)
    选择语句switch总结(七)
  • 原文地址:https://www.cnblogs.com/xxffxx/p/13614939.html
Copyright © 2011-2022 走看看