• 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;
     
    }
    
  • 相关阅读:
    CoreData学习-最好的一片文章
    Xcode4.6下添加百度地图ios版(BMapKit)详细教程(_BMKMapManager错误解决)
    NSSearchPathForDirectoriesInDomains用法
    编绎显示Unknown type name “CGFloat” 错误解决方法
    自动调整cell的高度
    sqlMapConfig约束
    PotPlayer左上角信息关闭
    松懈
    sql查询练习
    idea内容补充
  • 原文地址:https://www.cnblogs.com/xxffxx/p/13614939.html
Copyright © 2020-2023  润新知