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;
     
    }
    
  • 相关阅读:
    巧用系统命令看是否中毒
    从80年代初到2003年末中国出现的街头骗术
    万象数据库新密码世界```和原来的不同了
    换网关bat
    给自己的电脑做一个O盘 -隐藏自己私密的东
    一个小恶 搞 病 毒
    诊断卡常见代码
    路由跟踪命令的用法和技巧
    block,inline和inline-block的区别
    Jquery easyui开启行编辑模式增删改操作
  • 原文地址:https://www.cnblogs.com/xxffxx/p/13614939.html
Copyright © 2011-2022 走看看