Codeforces Beta Round #94 div2 D 优先队列
2 seconds
256 megabytes
standard input
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 < i) xj = 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.
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).
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).
aa
2
a
abc
5
bc
abab
7
b
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 = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
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=;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\n",s.a.c_str());
return;
}
if(s.st<len-)
{
s.a+=a[++s.st];
q.push(s);
}
}
printf("No such line.\n");
}
int main()
{
int x,y,z,i,t;
cin>>a;
scanf("%d",&x);
len=a.size();
k_big(x);
return ;
}
Codeforces Beta Round #94 div2 D 优先队列的更多相关文章
- 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces
题目传送门 /* 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) */ #include <cstdio> #include <cs ...
- BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues
题目传送门 /* BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到.因为雕像最多8步就会全部下落, 只要撑过这个时间就能win,否则lose */ #include <c ...
- Codeforces Beta Round #73(Div2)
A - Chord 题意:就是环中有12个字符,给你三个字符,判断他们之间的间隔,如果第一个和第二个间隔是3并且第二个和第三个间隔是4,那么就输出minor,如果第一个和第二个间隔是4并且第二个和第三 ...
- Codeforces Beta Round #94 (Div. 1 Only)B. String sam
题意:给你一个字符串,找第k大的子字符串.(考虑相同的字符串) 题解:建sam,先预处理出每个节点的出现次数,然后处理出每个节点下面的出现次数,然后在dfs时判断一下往哪边走即可,注意一下num会爆i ...
- Codeforces Beta Round #94 div 1 D Numbers map+思路
D. Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces Beta Round #94 div 2 C Statues dfs或者bfs
C. Statues time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces Beta Round #94 div 2 B
B. Students and Shoelaces time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Beta Round #107(Div2)
B.Phone Numbers 思路:就是简单的结构体排序,只是这里有一个技巧,就是结构体存储的时候,直接存各种类型的电话的数量是多少就行,在读入电话的时候,既然号码是一定的,那么就直接按照格式%c读 ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
随机推荐
- [py]flask实现用户cmdb
人最难做到的就是跟自己学习, 总是学习别人的, 沉淀, 过一段时间忘了刚学到的, 在向别人学习, 而非看看自己的沉淀, 殊不知, 世界上最亲近,最默契的人是自己. 用户cmdb功能概述 之前学flas ...
- selenium-python:登录网站并签到
测试网站的图像验证码统一设置成了:121 Elements中定位元素比较费眼睛~~ import time from selenium import webdriver # import os use ...
- [LeetCode] 513. Find Bottom Left Tree Value_ Medium tag: BFS
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 ...
- pop to 特定的UIViewController
1. 我们可以推出到特定的UIViewController 2. 有一个类没有navigationController,以前一般用delegate,我觉得我们可以把引用一个navigationCont ...
- PHP中header('content-type:text/html;charset="utf-8')和error_reporting()的作用
1.header PHP文件插入header("Content-type: text/html; charset=utf-8");相当于页面里面的<meta http-equ ...
- Fiddler过滤指定域名
Fiddler过滤指定域名的方法一 切换到fiddler右侧窗口的Filters选项卡,勾选顶部的“Use Filters”,找到Hosts区域,设置以下三个选项: 1.第一项有三个选项,不做更改: ...
- #C++初学记录(sort函数)
sort函数 前言:当进行贪心算法的学习时,需要用到sort函数,因为初学c++汇编语言,sort的具体用法没有深入学习,所以这里进行sort学习记录并只有基础用法并借用贪心算法题目的代码. 百度百科 ...
- js匿名自执行函数中闭包的高级使用(---------------------------******-----------------------------)
先看看最常见的一个问题: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- vue性能优化2--引入cdn
当我们加载页面时,需要将我们所需要的一些依赖加载到当前会话中然后再开始执行,如果我们首屏,模块比较多是,需要等待的时间会比较长,而且.浏览器内存最多执行四十个进程,需要等到加载完前面的才能执行后面的代 ...
- Trove系列(四)—Trove的快照功能介绍
Trove 快照用于支持DbaaS 备份,复制等功能.在Trove API (guest_agent)上将支持本功能.本功能将能够支持快照,从而用来进行副本设置,主数据库克隆和备份,以及数据恢复.目前 ...