zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #94 div2 D 优先队列

    B. String
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    One day in the IT lesson Anna and Maria learned about the lexicographic order.

    String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ j < ixj = yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages​​.

    The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the k-th string from the list. Help Anna and Maria do the homework.

    Input

    The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer k (1 ≤ k ≤ 105).

    Output

    Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes).

    Examples
    input
    aa
    2
    output
    a
    input
    abc
    5
    output
    bc
    input
    abab
    7
    output
    b
    Note

    In the second sample before string "bc" follow strings "a", "ab", "abc", "b".

    思路:优先队列;被c++卡死。。我是c++11过的

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    #define true ture
    #define false flase
    using namespace std;
    #define ll __int64
    #define inf 0xfffffff
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF )  return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    struct is
    {
        string a;
        int st;
        bool operator <(const is &x) const
        {
            return a>x.a;
        }
    };
    string a;
    int len;
    priority_queue<is>q;
    void k_big(int k)
    {
        is s;
        for(ll i=0;i<len;i++)
        {
            s.a=a[i];
            s.st=i;
            q.push(s);
        }
        while(!q.empty())
        {
            s=q.top();
            //cout<<s.a<<" "<<s.st<<endl;
            q.pop();
            k--;
            if(!k)
            {
                printf("%s
    ",s.a.c_str());
                return;
            }
            if(s.st<len-1)
            {
                s.a+=a[++s.st];
                q.push(s);
            }
        }
        printf("No such line.
    ");
    }
    int main()
    {
        int x,y,z,i,t;
        cin>>a;
        scanf("%d",&x);
        len=a.size();
        k_big(x);
        return 0;
    }
    View Code
  • 相关阅读:
    linux防止sshd被爆破(安装denyhosts)
    记一次网站服务器搬迁实录
    用几条shell命令快速去重10G数据
    如何让你的scrapy爬虫不再被ban之二(利用第三方平台crawlera做scrapy爬虫防屏蔽)
    同时运行多个scrapy爬虫的几种方法(自定义scrapy项目命令)
    如何让你的scrapy爬虫不再被ban
    scrapy爬虫成长日记之将抓取内容写入mysql数据库
    scrapy爬虫成长日记之创建工程-抽取数据-保存为json格式的数据
    python将json格式的数据转换成文本格式的数据或sql文件
    shell脚本去重的几种方法
  • 原文地址:https://www.cnblogs.com/jhz033/p/5456419.html
Copyright © 2011-2022 走看看