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;
     
    }
    
  • 相关阅读:
    五种常见的 PHP 设计模式(收藏)
    写年度工作总结
    关于window.open和window.showdialog返回值的问题
    50个令人叹为观止的JavaScript应用站点[转]
    10大免费FLV播放器下载[转]
    6个去掉图片上的文字的技巧实用简单
    mysql命令大全(转)
    10款替代Windows Media Player的播放器
    Editplus FTP远程访问Ubuntu
    C++ 元编程 Meta Programming
  • 原文地址:https://www.cnblogs.com/xxffxx/p/13614939.html
Copyright © 2011-2022 走看看