codeforces 128B. String
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|)),
thatxi < 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".
题意是给你一个字符串,找到其第k小的连续子序列。我们可以用set或者优先队列模拟,一开始把所有的单个字符放进去,然后每次取出set中最小的字符串,然后把这个字符串加上其后面一个字符放入set中继续排序,连续k次。这题结构体里不能用char str[100000],因为会爆内存,要用string.
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll int
#define inf 0x7fffffff
#define maxn 100005
char str[maxn],str1[maxn];
string ss;
struct node{
string s;
//char s[maxn];
int idx;
}a,b,temp,temp1,ans;
bool operator<(node a,node b){
return a.s<b.s;
}
multiset<node>myset;
multiset<node>::iterator it;
int main()
{
int n,m,i,j,len,tot;
while(scanf("%s",str)!=EOF)
{
len=strlen(str);
scanf("%d",&n);
myset.clear();
memset(str1,0,sizeof(str1));
for(i=0;i<len;i++){
str1[0]=str[i];
a.s=str1;
a.idx=i+1;
myset.insert(a);
}
tot=0;
while(!myset.empty()){
it=myset.begin();
temp=*it;
myset.erase(it);
tot++;
if(tot==n){
ans=temp;
break;
}
if(temp.idx<=len-1){
ss=temp.s;
ss=ss+str[temp.idx];
temp1.s=ss;
temp1.idx=temp.idx+1;
myset.insert(temp1);
}
}
if(tot==n){
cout<<ans.s<<endl;
}
else printf("No such line.\n");
}
return 0;
}
codeforces 128B. String的更多相关文章
- Codeforces 799D. String Game 二分
D. String Game time limit per test:2 seconds memory limit per test:512 megabytes input:standard inpu ...
- Codeforces - 828C String Reconstruction —— 并查集find()函数
题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...
- CodeForces 159c String Manipulation 1.0
String Manipulation 1.0 Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on Cod ...
- CodeForces 779D. String Game(二分答案)
题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
- Codeforces 710F String Set Quries
题意 维护一个字符串的集合\(D\), 支持3种操作: 插入一个字符串\(s\) 删除一个字符串\(s\) 查询一个字符串\(s\)在\(D\)中作为子串出现的次数 强制在线 解法 AC自动机+二进制 ...
- Codeforces 110B-Lucky String(技能)
B. Lucky String time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- CodeForces - 779D String Game 常规二分
题意:给你两个串,S2是S1 的一个子串(可以不连续).给你一个s1字符下标的一个排列,按照这个数列删数,问你最多删到第几个时S2仍是S1 的一个子串. 题解:二分删掉的数.判定函数很好写和单调性也可 ...
- Codeforces C - String Reconstruction
C - String Reconstruction 方法一:把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点. 代码: #include<bits/stdc++.h> ...
- CodeForces 828C String Reconstruction(并查集思想)
题意:给你n个串,给你每个串在总串中开始的每个位置,问你最小字典序总串. 思路:显然这道题有很多重复填涂的地方,那么这里的时间花费就会特别高. 我们维护一个并查集fa,用fa[i]记录从第i位置开始第 ...
随机推荐
- MySQL中的全局锁和表级锁
全局锁和表锁 数据库锁设计的初衷是解决并发出现的一些问题.当出现并发访问的时候,数据库需要合理的控制资源的访问规则.而锁就是访问规则的重要数据结构. 根据锁的范围,分为全局锁.表级锁和行级锁三类. 全 ...
- 攻防世界—pwn—hello_pwn
题目分析 下载文件后首先使用checksec检查文件保护机制 使用ida查看伪代码 思路明确,让dword_60106C == 1853186401即可输出flag 信息收集 偏移量 sub_4006 ...
- Vitis下载安装尝试
Vitis下载安装记录 一.下载安装 文章目录 一.下载安装 提示:以下是本篇文章正文内容,下面案例可供参考 一.下载安装 首先本次下载主要使用的是linux系统,所以我们先看一下Vitis支持的li ...
- IP2726中文规格书
IP2726_AC_FBR 是一款集成多种协议.用于USB-A 和 TYPE-C 双端口输出的快充协议 IC.支持多种快充协议,包括 USB TypeC DFP,PD2.0/PD3.0/PPS ,HV ...
- Django实现文件在本地的存储和读取
需求介绍:将图片存入本地的电脑文件夹中,将图片的路径保存到数据库,然后通过数据库的路径读取文件: 1.文件的存入: 前端文件: <form class="form-horizontal ...
- 太极图HTML+CSS(可旋转)代码记录
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Py装饰器
装饰器: 1.定义,什么是装饰器 装饰器本质是一个函数,它是为了给其他函数添加附加功能 2.装饰器的两个原则 原则1 不修改被修饰函数的源代码原则2 不修改被修饰函数的调用方式 3.首先来看一 ...
- Vue整合swiper报错Could not compile template .....swiper\dist\css\swiper.css解决办法
问题描述 今天做一个前端项目,安装幻灯片插件vue-awesome-swiper后 运行npm run dev 后报错如下: `ERROR Could not compile template E:\ ...
- elasticsearch从开始到永久
0.学习目标 独立安装Elasticsearch 会使用Rest的API操作索引 会使用Rest的API查询数据 会使用Rest的API聚合数据 掌握Spring Data Elasticsearch ...
- EMA algorithm: https://blog.csdn.net/m0_38106113/article/details/81542863
EMA algorithm: https://blog.csdn.net/m0_38106113/article/details/81542863