Smallest Substring
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
Given a string S and an integer K, your task is to find the lexicographically smallest string T which satisfies:
1. T is a subsequence of S
2. The length of T is K.
输入
The first line contain an integer K. (1 <= K <= 100000)
The second line contains a string of lowercase letters. The length of S is no more than 100000.
输出
The string T.
样例输入
4
cacbbac
样例输出
abac
package Daily;import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;public class Main_230 {public static void main(String [] args){Scanner scanner = new Scanner(System.in);int T = scanner.nextInt();String s = scanner.next();PriorityQueue<Node> queue = new PriorityQueue<>(Math.max(s.length() - T, 1), new Comparator<Node>() {@Overridepublic int compare(Node o1, Node o2) {if(o1.c == o2.c) return o1.index - o2.index;return o1.c - o2.c;//return 0;}public boolean equals(Object obj){return false;}});for(int i =0; i< s.length() -T ; i ++){queue.add(new Node(s.charAt(i) , i));}int ind = -1;int len = s.length() -T;while(T -- != 0){queue.add(new Node(s.charAt(len),len ++));Node node;do{node = queue.remove();}while(node.index <= ind);ind = node.index;System.out.println(node.c);}}static class Node{private char c;private int index;public Node(char c, int index){this.c = c;this.index = index;}}
}
Smallest Substring相关推荐
- 1198 Substring
Substring Time limit: 1 second(s) Memory limit: 32768 KBytes Total Submit : 1767 Accepted Subm ...
- [SPOJ7258]Lexicographical Substring Search
[SPOJ7258]Lexicographical Substring Search 试题描述 Little Daniel loves to play with strings! He always ...
- 1198. Substring
1198. Substring Description Dr lee cuts a string S into N pieces,s[1],-,s[N]. Now, Dr lee gives you ...
- Java substring使用时有哪些注意事项?
首先,使用substring截取字符串时,可能会出现两种异常,分别是StringIndexOutOfBoundsException和NullPointerException. 即字符串索引越界异常 与 ...
- leetcode 30. Substring with Concatenation of All Words 与所有单词相关联的字串 滑动窗口法
题目描述 给定一个字符串 s 和一些长度相同的单词 words.在 s 中找出可以恰好串联 words 中所有单词的子串的起始位置. You are given a string, s, and a ...
- leetcode Longest Substring with At Most Two Distinct Characters 滑动窗口法
题目解析 代码如下 题目解析 这一题是一道会员的题目,题目介绍如下: Given a string, find the length of the longest substring T that c ...
- js中substr,substring,indexOf,lastIndexOf的用法
js中substr,substring,indexOf,lastIndexOf等的用法 1.substr substr(start,length)表示从start位置开始,截取length长度的字符串 ...
- JavaScript中substr()和substring的区别
例子: var letters = "abcdefg"; console.log(letters.substr(1,3))//结果为bcd console.log(letters. ...
- LeetCode.3-最长无重复字符子串(Longest Substring Without Repeating Characters)
这是悦乐书的第341次更新,第365篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第2题Longest Substring Without Repeating Cha ...
最新文章
- 介绍一个好用的能让网页变成黑色背景的护眼 Chrome 扩展应用 - Night Eye
- ASP.NET 图片剪辑控件
- GitHub上12k Star的《Java工程师成神之路》中终于开放阅读了!
- 社群广场程序公众号版本程序源码-支持群采集
- 乐观锁与悲观锁及其实现
- java+mysql中文乱码解决
- pygame模块_pygame模块方法和事件
- 类/对象/构造函数/析构函数
- mysql md5全库比较_关于mysql搭建亿级cmd5数据库,毫秒级查询(完整过程)
- 人群疏散matlab程序,人群疏散方法及系统与流程
- excel文件被写保护怎么解除_u盘被写保护怎么解除_u盘怎么解除写保护状态
- word插入公式为灰色解决办法
- Ubuntu 20.04LTS 搜狗输入法不显示图标
- 亿格瑞A5-hdmi故障了
- 如何利用python调用API接口获取数据进行测试
- 获取手机存储卡路径的一种方法
- 【转载】最新读《你当像鸟飞往你的山》读后感心得体会5篇精选
- 【转】 机器学习入门——浅谈神经网络
- F函数的极大极大算法
- 基于SRS搭建RTMP直播流媒体服务器
热门文章
- 2019年电赛电磁炮,冲刺国赛
- 工作纪实_25-SpringCloud整合sentinel问题汇总
- 入驻园区享受税收优惠政策注意事项有哪些?税收返还
- Java圆的测试类_java – 最有效的方法来测试数字是否在360度圆的某个22.5度范围内...
- 关于php:如何在Guzzle中读取响应有效的URL?6.0(Guzzle获取重定向后的实际请求地址URL)
- C语言中各种数据类型的储存大小
- Sigmoid函数(logsig)求导
- 关于直接下载pdf文件以及地址栏参数隐藏问题
- jQuery+d3绘制流程图
- Camera/Lens流程(三)——Sensor Driver Check