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位置开始第 ...
随机推荐
- 立完flag,你可能需要对flag进行量化
DevUI是一支兼具设计视角和工程视角的团队,服务于华为云DevCloud平台和华为内部数个中后台系统,服务于设计师和前端工程师. 官方网站:devui.design Ng组件库:ng-devui(欢 ...
- 【Linux】NFS相关小问题
NFS一些小问题: 1. 由于实验环境中,给了rw权限,但是执行的时候,还是提示Permission denied 于是查看nfs服务端,查看/etc/exports文件是否配置有问题 网上很多人配置 ...
- Tippy.js - 免费开源且高度可定制的气泡提示独立组件
推荐一个非常优秀的 web 气泡提示独立UI组件. 介绍 Tippy.js 是一款用于Web的完整工具提示,弹出菜单,下拉菜单和菜单解决方案.适用于鼠标,键盘和触摸输入. 特点 超轻量的纯 javas ...
- CTFHub - Web(五)
eval执行: 1.进入网页,显示源码, <?php if (isset($_REQUEST['cmd'])) { eval($_REQUEST["cmd"]); } els ...
- Linux—curl命令讲解
命令:curl 在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具 ...
- RSA共模攻击
在安恒月赛中碰到一道密码学方向的ctf题 附上源码 from flag import flag from Crypto.Util.number import * p=getPrime(1024) q= ...
- 使用Adobe Arcobat Pro DC生成PDF提示“PDFMaker文件遗失”新解决思路
环境: 1.Window 7 2.Adobe Arcobat Pro DC 2020.009.20065 3.Microsoft Office 2007 4.WPS 2019 虽然可以使用插件实现文件 ...
- 被集群节点负载不均所困扰?TKE 重磅推出全链路调度解决方案
引言 在 K8s 集群运营过程中,常常会被节点 CPU 和内存的高使用率所困扰,既影响了节点上 Pod 的稳定运行,也会增加节点故障的几率.为了应对集群节点高负载的问题,平衡各个节点之间的资源使用率, ...
- 前端面试之CSS常用的选择器!
前端面试之CSS常用的选择器! 标签选择器 <style> /* <!-- 标签选择器 :写上标签名 -->*/ p { color: green; } div { color ...
- 华为三层交换机限制vlan段的指定端口
屏蔽vlan 120这个段的ip的所有2333端口 [NTT_3L]int Vlanif 120 [NTT_3L-Vlanif120]dis this # interface Vlanif120 ip ...