ARC097C K-th Substring
题目
You are given a string s. Among the different substrings of s, print the K-th lexicographically smallest one.
A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not. Also, we say that substrings are different when they are different as strings.
Let X=x1x2…xn and Y=y1y2…ym be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or xj>yj where j is the smallest integer such that xj≠yj.
Constraints
- 1 ≤ |s| ≤ 5000
- s consists of lowercase English letters.
- 1 ≤ K ≤ 5
- s has at least K different substrings.
Partial Score
- 200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.
Input
Input is given from Standard Input in the following format:
s
K
Output
Print the K-th lexicographically smallest substring of K.
题目大意
给你一个字符串s,求它字典序第k大的字串
分析
因为k<=5,所以我们可以枚举字串的起始点和长度,以为长度小,我们把整个字串转化成数字然后排序即可,注意长度不满k的字串在末尾要补零
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
long long a[110000];
map<long long,bool>app;
int cnt;
long long go(string s,int le,int ri){
int i,j,k;
long long res=0;
for(i=le;i<=ri;i++)
res=res*100+(s[i]-'a'+1);
for(i=ri-le+2;i<=5;i++)
res*=100;
return res;
}
int main()
{ int n,m,i,j,k;
string s;
cin>>s;
n=s.length();
cin>>k;
for(i=0;i<n;i++)
for(j=i;j<=min(i+k,n-1);j++){
long long res=go(s,i,j);
if(!app[res]){
a[++cnt]=res;
app[res]=1;
}
}
sort(a+1,a+cnt+1);
char c[110];
cnt=0;
while(a[k]){
if(a[k]%100)c[++cnt]=(a[k]%100-1)+'a';
a[k]/=100;
}
for(i=cnt;i>0;i--)
cout<<c[i];
return 0;
}
ARC097C K-th Substring的更多相关文章
- LeetCode第[5]题(Java):Longest Palindromic Substring 标签:String、动态规划
题目中文:求最长回文子串 题目难度:Medium 题目内容: Given a string s, find the longest palindromic substring in s. You ma ...
- sql 取汉字首字母
)) ) --用于加密 --WITH ENCRYPTION as begin declare @intLen int ) ) set @intLen = len(@str) set @strRet = ...
- sql 函数 汉字转拼音
GO /****** Object: UserDefinedFunction [dbo].[fn_GetPy] Script Date: 2017/1/4 10:53:49 ******/ SET A ...
- Pjax调用
$.pjax({container:'#content_center',url:href,data:data}); $(document).on('pjax:send', function() {// ...
- 都别说工资低了,我们来一起写简单的dom选择器吧!
前言 我师父(http://www.cnblogs.com/aaronjs/)说应当阅读框架(jquery),所以老夫就准备开始看了 然后公司的师兄原来写了个dom选择器,感觉不错啊!!!原来自己从来 ...
- Leetcode: Encode String with Shortest Length && G面经
Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...
- JAVA时间格式转换大全
import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @return 返回时间类型 ...
- Spark中常用工具类Utils的简明介绍
<深入理解Spark:核心思想与源码分析>一书前言的内容请看链接<深入理解SPARK:核心思想与源码分析>一书正式出版上市 <深入理解Spark:核心思想与源码分析> ...
- sql拼音简写函数
USE [HotelDB]GO /****** Object: UserDefinedFunction [dbo].[fn_GetPy] Script Date: 2016/1/4 13:29:13 ...
- SQL将用户表中已存在的数据所有姓名(汉字)转换为拼音首字母
实现方法: --函数 Create function [dbo].[fn_GetPy](@str nvarchar(4000)) returns nvarchar(4000) --用于加密 --WIT ...
随机推荐
- [转] 在Mac上搭建React Native开发环境
原文链接: http://blog.csdn.net/xiangzhihong8/article/details/53914336 概述 前面我们介绍过在window环境下开发React Native ...
- 算法(Algorithms)第4版 练习 1.5.10
Yes, but it could increase the tree height, so the performance guarantee would be invalid.
- 算法(Algorithms)第4版 练习 1.3.7
package com.qiusongde; import java.util.Iterator; import java.util.NoSuchElementException; import ed ...
- ML二(决策树学习)
决策树学习 Decision Tree Learning 1 基本概念 属性(attribute):树上的每个结点说明了对实例的某个属性的测试,该结点的每一个后继分支对应该属性的一个可能值. 熵(en ...
- Qt之界面实现技巧-- 窗体显示,绘制背景,圆角,QSS样式
转自 --> http://blog.sina.com.cn/s/blog_a6fb6cc90101dech.html 总结一下,在开发Qt的过程中的一些技巧!可遇而不可求... 一.主界面 1 ...
- Codeforces 337D Book of Evil:树的直径【结论】
题目链接:http://codeforces.com/problemset/problem/337/D 题意: 给你一棵树,n个节点. 如果一个节点处放着“罪恶之书”,那么它会影响周围距离不超过d的所 ...
- Java的TCP网络编程
服务端代码: package socket; import java.io.BufferedReader; import java.io.IOException; import java.io.Inp ...
- 二 Django框架,urls.py模块,views.py模块,路由映射与路由分发以及逻辑处理——url控制器
Django框架,urls.py模块,views.py模块,路由映射与路由分发以及逻辑处理——url控制器 这一节主讲url控制器 一.urls.py模块 这个模块是配置路由映射的模块,当用户访问一个 ...
- appium-环境搭建(三)
appium步骤:基本环境1.由于操作手机端操作,需要模拟器或者真机 itools模拟器,真机2.appium操作app,需要知道操作的app是什么?需要知道这个app包名 1.问开发 2.利用adt ...
- linux-常用指令1
掌握下面的命令是最基本的噢!那是我们使用一个系统最基本的操作. 玩过dos么,其实,linux下的文件操作和dos差不多.没什么难的,多练习就记住了.下面如果有条件的话请跟我一样操作吧!百看不如一做. ...