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位置开始第 ...
随机推荐
- JavaFX之班级未交作业统计
前言 最近转移了系统平台,用上了Ubuntu1804版本系统,原来用C#写的Windows窗体软件也不能用了,而且自己在班级上每周都需要收作业,所以写了这个软件.这篇博客主要记录这个JavaFX应用的 ...
- python模块详解 | selenium(持续更新中)
目录: 关于selenium Selenium 安装Selenium 安装浏览器驱动 配置环境变量 selenium方法详解 定位元素 元素操作 浏览器操作 鼠标事件 浏览器事件 设置元素等待 多表单 ...
- 【Linux】云服务器部署宝塔linux控制面板环境
服务器购买及宝塔部署环境说明 简单记录 - 狂神的 服务器购买及宝塔部署环境说明 服务器如何购买 我们尽量趁打折的时候购买,比较便宜点!多看看有活动. 如果是学生,可以购买学生机, 学生机地址:htt ...
- 【MySQL】使用MySQL(连接、选择数据库、显示数据库和表信息)
第3章 使用MySQL 文章目录 第3章 使用MySQL 连接 选择数据库 了解数据库和表 小结 简单记录 - MySQL必知必会 - [英]Ben Forta 将学习如何连接和登录到MySQL,如何 ...
- kubernets之服务重定向
一 服务的强大功能之处的其他表现 前面介绍的所有有关服务的说明,都是将集群内部的pod应用暴露出来提供外部客户端或者内部的客户端进行访问,但是服务的强大之处远远不止于此 服务甚至可以将集群外部的应用 ...
- 使用sqluldr2进行oracle数据库抽取时执行后无反应,也无日志
使用sqluldr2进行oracle数据库表数据抽取时遇到执行后无反应,也不报错,也无日志输出的情况. 经过排查之后发现时由于oracle账户密码快要过期导致的(这也能出问题,我服,类似的plsql连 ...
- 两行代码修复了解析MySQL8.x binlog错位的问题!!
写在前面 MySQL是互联网行业使用的最多的关系型数据库之一,而且MySQL又是开源的,对于MySQL的深入研究,能够加深我们对于数据库原理的理解.自从开源了mykit-data之后,不少小伙伴试用后 ...
- File Inclusion - Pikachu
概述: 文件包含,是一个功能.在各种开发语言中都提供了内置的文件包含函数,其可以使开发人员在一个代码文件中直接包含(引入)另外一个代码文件. 比如 在PHP中,提供了: include(),inclu ...
- 使用pushplus+python实现亚马逊到货消息推送微信
xbox series和ps5发售以来,国内黄牛价格一直居高不下.虽然海外amazon上ps5补货很少而且基本撑不过一分钟,但是xbox series系列明显要好抢很多. 日亚.德亚的xbox ser ...
- 《UML与设计原则》--第四小组
关于设计模式与原则 一.设计模式简介 设计模式描述了软件设计过程中某一类常见问题的一般性的解决方案.而面向对象设计模式描述了面向对象设计过程中特定场景下.类与相互通信的对象之间常见的组织关系. 二.G ...